7.3. The file Class

AppleScript has a file class that you use with certain commands to reference a file or folder. You can create a file object for a file or directory simply by inserting the specifier file in front of a traditional path name like this:

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

The class of the result produced by this expression is identified by AppleScript as a file specification.

You can also specify a file using a POSIX path name by placing POSIX file in front of the path name:

POSIX file "/Users/chris/Documents/resume.doc"

When you compile this line, Script Editor changes it to look like the previous command:

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

The way AppleScript deals with files can be confusing. In the case of the first file... example, AppleScript creates a file specification from the specified file name. In the case of the POSIX file example, a file URL is created, even though after the line is compiled it appears identical to the first example. You don't need to concern yourself with this difference.

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.