Jump to content

AppleScript Programming/Aliases and paths

From Wikibooks, open books for an open world

Paths can appear in the following format in AppleScript which is a carryover from Classic Mac OS. This type of path name is called HFS which is short for "Hierarchical File System".

<Volume Name>:<Directory Name>:...:<Directory Name>:<Filename>

For example, the following is an example an HFS path name

Macintosh HD:Applications:Safari.app

HFS paths are different than the current OS X standard, called w:POSIX paths. The POSIX style comes from OS X's Unix heritage. Notice that in HFS path names, a colon ":", is used as a separator, and in POSIX path names, a forward slash "/" is used as a separator. The other major difference is that in HFS path names, the path name begins with the name of the volume and in POSIX path names, the startup volume doesn't need to be named, only other volumes need to be named.

Because of the history of OS X with both a Classic Mac OS history and a Unix history both HFS paths and POSIX paths are still useful and in AppleScript you sometimes have to convert from one standard to the other, depending upon which kind of path name is needed.

The following example of a POSIX path specifies the application Safari.app which is contained by the Applications folder on the start up disk.

/Applications/Safari.app

Converting between formats

[edit | edit source]

Assuming oldPath would be an alias or record of a finder item, use the following command to set a standard Applescript alias to a POSIX path:

 set thisPOSIXPath to (the POSIX path of oldPath)
 -- input: "Macintosh HD:Applications:Safari.app"
 -- output: "/Applications/Safari.app"


To convert a POSIX path to a standard Applescript alias (the inverse of the above command), use this command:

 set newerPath to POSIX file newPath as alias -- omit 'as alias' to get a file object
 -- input: "/Applications/Safari.app"
 -- output: "Macintosh HD:Applications:Safari.app"