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!


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.


You can get the machine name with scutil --get ComputerName and the name of the boot volume with

basename "`find -x /Volumes/ -type l`"

Note that both of these may well return a string containing spaces. So you want to do this

COMPUTER="`scutil --get ComputerName`"
VOLUME="`basename \"\`find -x /Volumes/ -type l\`\""


TIMEPATH="/Volumes/Time Machine/Backups.backupdb/$COMPUTER/$VOLUME/Users"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .