AppleScript_ The Definitive Guide - Matt Neuburg [126]
The style resource can be used (perhaps one should say "misused") as a way of carrying encoding information, by associating a font with an encoding. When you coerce an alias to a string, for example, AppleScript actually returns styled text, on the off chance (I suppose) that if the pathname contains any characters outside the MacRoman encoding, the extra encoding information in the style resource can help represent them. But AppleScript conceals from you the fact that it's doing this:
class of ((path to desktop) as string) -- string
Despite AppleScript's answer here, the result is really styled text. As before, we can detect this fact by coercing to a record:
(path to desktop) as string
result as record -- {«class ktxt»:"feathers:Users:mattneub:Desktop:",
«class ksty»:«data styl0001000000000010000E00030000000C000000000000»}
Similarly, any Unicode text coerced to a string is secretly coerced to styled text:
"howdy" as Unicode text as string as record -- {«class ktxt»:"howdy",
«class ksty»:«data styl0001000000000010000E00030000000C000000000000»}
To make things even more complicated, international text and styled text sometimes give the impression of being interchangeable. For example:
get name of application "Tex-Edit Plus"
According to Tex-Edit Plus's dictionary, the result should be international text, but in fact it is styled text. All this is fairly mystifying, and the undeniable impression is that AppleScript text handling is messy and it's trying to conceal the mess (mostly by sweeping it under the carpet).
File and Alias
A file object is a reference to a file or folder on disk. To construct one, use an object string specifier —the word file followed by a string representing a colon-delimited pathname:
file "feathers:Users:mattneub:"
By "colon-delimited" I mean an old-style Macintosh -type path. This is not the same as the new-style Unix-type path (new to Mac users, anyway), also known as a POSIX path. AppleScript has a long history on Macintosh, so it is not surprising that its native representation of file paths is not the Unix representation. Macintosh paths start with a disk name, and the delimiter between the disk name, folder names, and filename is a colon. A pathname ending in a colon is a folder or a disk. (A partial pathname, one whose first element is not a disk, is taken to start inside the "current directory," but the interpretation of this notion is unreliable, and partial pathnames should be avoided.)
Oddly, you can't assign a file object specifier to a variable, or return it as a value. If you try, you get a runtime error message:
set x to file "feathers:Users:mattneub:"
-- error: Can't make file "feathers:Users:mattneub:" into type reference
Instead, you must generate a reference to the file object, like this:
set x to a reference to file "feathers:Users:mattneub:"
x -- file "feathers:Users:mattneub:" of «script»
A file specifier is not resolved until the script actually runs. This means that the item on disk need not exist at compile time. At runtime, however, when the file specifier is handed to some command, either the item must exist, or, if the command proposes to create it, everything in the path must exist except for the last element, the name of the item you're about to create. Otherwise the command will generate a runtime error on the grounds that it can't find or create the item. We've already met one command that accepts a file specifier to create a file—store script (see "Compiled Script Files as Script Objects" in Chapter 8).
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:
If an alias specifier uses a literal pathname string, then the item on disk that it represents must exist at compile time.
If an alias specifier