How to specify a drive in Applescript without the drive name

applescript

I had a main system drive on my iMac named "Macintosh HD" and wrote my scripts to reference files on that drive. For instance, to get to my library directory, I had "Macintosh HD:Users:me:Documents:Dev:AppleScript:" as the full path.

The problem is that I'm having drive issues and need to replace my drive before it goes bad. To keep track, I cloned my original system drive ("Macintosh HD") to "System Temp," which is connected by USB. I can afford to use this drive for a few days, but need to return it to a server as soon as I can. Early this week I'll be getting a new drive that will be the long term replacement drive, named, "System."

I don't want to name each drive "Macintosh HD" because that makes it hard for me to keep track of them, but I'd like to keep the scripts working throughout the process.

How can I, in Applescript, specify a pathname to a drive without using the HD name? If it's the main HD, what is the equivalent of the Linux form of "/" for the root file system, so I'd use "/home/me" to get to my home directory? Is there some way to do something like "::Users:me" instead? I just want to be able to tell Applescript something like, "This is on the main system drive," or, "Use the boot drive."

I tried a lot of possible alternatives and none worked.

Best Answer

Instead of using HFS file paths, use posix paths.

Use System Events for file operations, which handles posix paths as well as HFS paths. It even knows how to expand the ~, so your home directory can be expressed simply as folder "~/", and your main disk is mounted at folder "/".

As for your attached USB drives, you essentially have to reference them by name. They'll be listed under folder "/Volumes", or you can use this command (via System Events):

get the name of every disk where it is ejectable -- i.e. attached drives

I'm not entirely able to tell if I've answered all your questions. Leave a comment and I'll fill in whatever seems missing.