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.


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.

| improve this answer | |
  • I tried changing "Macintosh HD:Users:me:Documents:Dev:AppleScript:" to "/Users/me/Documents/Dev/Applescript" and it won't work. I'm adding more. This is for a utility library of mine and I think part of the problem is I'm trying to load this library as a script. The line that seems to be a problem is "set MyUtil to load script pathMyUtil." – Tango Jul 13 at 15:18
  • 1
    Your two paths are indeed equivalent, but to access the folder in question, you need to reference it through System Events, i.e. tell app id "com.apple.systemevents" to set scptdir to folder "~/Documents/Dev/AppleScript". load script is a Standard Additions command, all of which understand posix paths without needing to be qualified. Therefore, if pathMyUtil has the value "/Users/me/Documents/Dev/AppleScript/utils.scpt" (or whatever the file is called), then load script pathMyUtil is all good. (Although note that use of the tilde only works in a SystemEvents context.) – CJK Jul 13 at 15:41

You must log in to answer this question.

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