7.1. Path Names: Traditional Mac and POSIX-style

You probably know that Mac OS X is based on the UNIX operating system. UNIX uses a different notation to identify files from what is traditionally used to identify files on the Mac. For example, the traditional Mac path to a file called resume.doc in your Documents folder might be expressed as follows:

Macintosh HD:Users:chris:Documents:resume.doc

When expressed as a POSIX path name, it looks like this:

/Users/chris/Documents/resume.doc

POSIX is the name of a UNIX standard that emerged in the 1980s from the IEEE committee. It was created in an effort to standardize the different versions of UNIX that existed at the time.

If the last component of a path is a folder, a trailing : character is used when writing the traditional path to the folder, like so:

Macintosh HD:Users:chris:Documents:

In the case of a POSIX path name, you can put a trailing slash at the end of the path, but it's optional to do so:

/Users/chris/Documents/

Path names are typically expressed as strings in AppleScript. For example, the path to Chris's Documents folder might be written like this:

set docsPath to "Macintosh HD:Users:chris:Documents:"

You can ask AppleScript to give you the POSIX-equivalent path name for a traditional path name by asking for the POSIX path property of the path name like this:

set docsPath to POSIX path of "Macintosh HD:Users:chris:Documents:"

This sets the variable docsPath to the string

/Users/chris/Documents/

because on my system, ...

Get Beginning AppleScript® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.