MacOS – Universal path in Terminal

applescriptmacosterminaltime-machine

I'm writing an AppleScript that will allow me to copy the Time Machine folder from an external drive and paste it onto the user's desktop of their Mac. The reason I'm doing this is because when a time machine backup isn't working as it should, we have to manually move it. Well, I'd like to make this process easier for people and just create a script to do it.

tl;dr problem:
How do I make a variable location?

Ex: /Volumes/Time\ Machine/Backups.backupdb/?/?/Users

The X and Y are going to be different for everyone's Mac. People have different names for their macs and Hard Drives. How could I make a universal location? Thanks!

Best Answer

You can use the ~ shortcut or $HOME variable, both of which refer to the User's home directory. You can try this out in Terminal by running cd ~ or cd $HOME, which will take you to your home directory. You can verify by running pwd, which should output /Users/ followed by your username.

For the Desktop, you would use ~/Desktop or $HOME/Desktop.