Alias

An alias object is very much like a file object. You can form an alias specifier in just the same way as you form a file specifier, and an alias object can often be used in the same places where a file object would be used. But there are some important differences:

  • The item on disk represented by an alias specifier must exist at compile time.

  • A pathname string or a file object can be coerced to an alias. (But a file specifier can’t be coerced to an alias in the current Script Editor. I regard this as a bug, since it works fine in the old Script Editor.)

  • An alias can be assigned directly to a variable as its value.

  • An alias is an alias. That means it has the wonderful ability of a Macintosh alias to continue pointing to an item on disk even if the item is moved or renamed.

Alias objects are commonly used by scriptable applications as a way of returning a pointer to an item on disk. For example:

tell application "BBEdit"
        get file of window 1 -- alias "xxx:Users:mattneub:someFile"
end tell

In that code, the term file is merely the name of a window property, and has nothing to do with the file class from the previous section. (Well, almost nothing. Its raw four-letter code is the same as that of the file class. See Chapter 19.)

Again, don’t be confused by classes belonging strictly to a particular scriptable application; the Finder’s alias file class, for example, is not an alias.

There is a long-standing confusion in AppleScript about how to specify the file to which a new document ...

Get AppleScript: The Definitive Guide 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.