File Coercions
An
alias can be coerced to a string
representing its Macintosh
pathname, and its POSIX path property is a string representing its POSIX pathname.
An alias cannot be coerced to a file object, but a string can be used
as an intermediary. A Macintosh pathname can be coerced to an alias.
A file object cannot be coerced to a string, but it can be coerced to
an alias (which can be coerced to a string). A
file’s POSIX path property is a
string representing its POSIX pathname. A POSIX file can be coerced
to a string representing its Macintosh pathname. A Macintosh pathname
can be used to form a file specifier. A POSIX pathname can be used to
form a POSIX file specifier. (I’m not making this
up!)
I believe that the possibilities are summed up by the following code:
set colonPath to "main:reason:resources:" set a to alias colonPath set a to colonPath as alias set colonPath to a as string set posixPath to POSIX path of a set f to a reference to file colonPath set a to f as alias set posixPath to POSIX path of f set pf to POSIX file posixPath set colonPath to pf as string set posixPath to POSIX path of pf set a to pf as alias
Just to make matters more confusing, coercion of a file specifier to an alias fails in the current Script Editor. To work around this, pass through a POSIX file:
set colonPath to "main:reason:resources:" set f to a reference to file colonPath set posixPath to POSIX path of f set pf to POSIX file posixPath set a to posixFile as alias
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access