AppleScript file reference forms

by: 
Last modified: Feb 15, 2014 12:49 PM
0 6266 Last modified Feb 15, 2014 12:49 PM

In AppleScript there are several different ways of specifying particular files and folders on a disk. They will all refer to the same file or folder, obviously, but they are not always - or even often - interchangeable. Knowing what the various forms are, and which should be used where, will save a lot of unnecessary headaches.


HFS paths

Format: Disk:folder:folder:file

Example: "Macintosh HD:Applications:TextEdit.app'


HFS paths always begin with the name of the disk the file is located on. The system will see them as strings, not file references, unless they are prefixed with a keyword such as alias or file, but the strings are often useful for passing file references between different applications.


POSIX paths

Format: /folder/folder/file

Example: "/Applications/TexEdit.app


POSIX paths always begin with a slash that represents the startup volume; unlike HFS paths, the startup volume name is never included. Other disk are referred to by their mount points, usually /Volumes/Diskname/.


  • POSIX paths are required when dealing with unix (as in the do shell script command), and some applications prefer them over other reference forms.
  • The Finder does not understand POSIX paths, and will throw errors if you try to use them.

Applescript file references and aliases

Format: file <HFSpath> or alias <HFSpath>

Example: alias "Macintosh HD:Applications:TextEdit.app"


File references and aliases are machine-level representations of file paths. Applescript error messages will sometimes refer to them as 'ints', because applescript sees them as long integers. Aliases must point to existing files or folders or they will throw an error. Use the file keyword to make a reference to a non-existent file.


Finder object references

Format: a string of keywords and names that specify the file position as nested objects

Example: application file "TextEdit" of folder "Applications" of disk "Macintosh HD" or disk "Macintosh HD"'s folder "Applications"'s application file "TextEdit"


Finder object references are only recognized by the Finder and by System Events.app. They are useful for working with files and folders in an object-oriented manner. The Finder and System Events have slightly different syntaxes, so check their scripting dictionaries to see what keywords are available. They both have an assortment of shortcut keywords for important objects like the user's home folder or the startup disk.


As a rule, prefer to use System Events.app over the FInder. System Events is much faster and far less likely to crash. That being said, there are certain things that can only be done in the Finder (such as setting label colors).


  • The Finder does not understand POSIX paths, but System Events does.
  • 10.6 and later put restrictions on calling handlers from inside application tell blocks, so some things that look like they should work - e.g. calling the path to command of the Standard Additions osax - will not work. Again, the Finder is touchier about this than System Events.


The following commands and properties are useful for dealing with file references. Most of them can be found in the dictionary for the Standard Additions osax.


  • path to [...]. Use this command to find aliases to standard OSX folders, installed applications, or resources in a bundled applescript or script app
  • POSIX file [POSIX path]. This command converts a POSIX path string to an applescript file reference
  • POSIX path of [file ref]. This property of applescript file references returns a POSIX string for given reference
  • quoted form of [POSIX path]. This command adds quotes to a POSIX path string so that it will function correctly in a shell command. Use this with file paths that may contain spaces or other characters with special meaning in unix shells.
Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.