Suppose I have created an alias on my desktop of the file ‘report.cwk’ which file is in my folder
‘Documents’. Now, if I were to move the file ‘report.cwk’ from the folder ‘Documents’ to another
location, double-clicking the alias would still open the file. Great! I may even rename the original
file ‘report.cwk’ to something else, such as ‘funny_story.cwk’. That is because the alias does
not store the location (and name) of the file ‘report.cwk’ as
but rather as a kind of ID. The Finder maintains a database of these IDs together with the
current whereabouts of the corresponding files (and folders and applications, for that matter).
So, if I move the file ‘report.cwk’, its unique ID remains the same, but the Finder changes its
internal database to reflect the new location of the file. When I double-click the alias, the ID
contained by it is used by the Finder to find out which file corresponds to the ID, and the
Finder will open the correct file.
To have a script that does not break if the file (or folder) a script refers to is removed or
renamed, our script should contain the ID of the file (or folder), instead of a ‘hard-coded’ path.
AppleScript allows for this .
set thePath to alias "Macintosh HD:Users:ik:Documents:report.cwk"
It is very important to note that the statement of script  refers to the original file present in the
folder ‘Documents’, and not some user-created alias of that file, like the one I purported to
have on my desktop. In the statement of script , ‘alias’ is a keyword indicating that,
compilation (i.e. checking of the syntax), the script should remember the ID of the file and,
upon execution, should not ask the Finder for a file at the location as specified by the defined
path, but based on the ID.
If you run the script , and check its result in the result field, it looks like this:
So, you do not get to see the ID itself. However, the word ‘alias’ before the path tells you that
internally the script works with the ID, and not with a hard-coded path. Now, with the script
being compiled, move the file ‘report.cwk’ to another location and run the script again. I moved
the file into a folder named ‘Miscellaneous’ inside my folder ‘Documents’. Even though the
script, and in particular the path in script , has not changed, the result now is
alias "Macintosh HD:Users:ik:Documents:Miscellaneous:report.cwk"
Try this yourself (again, your path looks different because of your login name that is probably
not ‘ik’ and perhaps because you may use different folder names)! If you save the script as a
compiled script or an AppleScript application, the ID is stored, and next time you run the
script, it will perform flawlessly even if you moved or renamed the original file. It should not
surprise you that the script will fail if the file has been deleted.
In summary, you have two ways of dealing with paths in scripts. You can either specify a file
location (hard-coded, using file “
), or you can use the ‘alias’ keyword to make the