AppleScript_ The Definitive Guide - Matt Neuburg [176]
Value Types
There are many places where a dictionary specifies a value's type. Every property is of some type, and the dictionary tells you what it is. (Examples appear in Figure 20-2; a disk object's capacity is a double integer, its ejectable is a boolean, and so forth.) Each of a command's parameters is of some type, and the command's returned value, if any, is of some type (Figure 20-4).
Figure 20-2. The dictionary display in Script Editor 2.1
In the dictionary itself, such value types are expressed as four-letter codes. Such a four-letter code may designate a built-in AppleScript datatype (see Chapter 13) or a class defined by the application (see "Enumerations" and "Classes," later in this section). This allows, say, iTunes's dictionary to specify that a value should be a string or a track. However, this is not enough to express all that a dictionary might want to tell you, so the dictionary specification permits certain further value types and options:
anything
A complete wildcard type ('****'). Might appear as "any ."
reference
A less wild wildcard type ('obj '), indicating that the value is some object belonging to the application. Might appear as "specifier."
Figure 20-3. The dictionary display in Script Debugger 4 (abbreviated)
location reference
A relative element specification ('insl'). See "Relative" in Chapter 11. Might appear as "insertion location ."
Figure 20-4. A command as displayed in Script Editor
type class
A class; a datatype ('type'). Might appear as "type." See "Class" in Chapter 11.
property
A property ('prop'). Might appear as "property specifier ."
list of
A type may be qualified in the dictionary to indicate a list of that type (like "list of alias" in Figure 20-4).
or
Where a limited set of alternative types is legal, these may be specified explicitly, separated by "or." Historically, this option is rarely used. The sdef format makes it easier to implement, so we may see more of this sort of thing in the future.
Value type information is for the human reader only. The AppleScript compiler, for example, does not check to see whether the value you actually supply as a command parameter or to set a property is of the type specified by the dictionary; and the runtime engine doesn't care what type of value a scriptable application returns.
This being so, it is difficult to see why the dictionary specification requires that types be encoded as four-letter codes; four-letter codes are a machine-readable format, but no machine is going to read this information. The communicative worth of value types in the dictionary is thus limited unnecessarily.
Take, for example, iTunes's convert command. Its direct object is described in the dictionary as list of reference. This is both too restrictive and too general. It's too restrictive because the direct object need not be a list. It's too general because "reference" could mean anything, whereas in fact what iTunes wants is quite specific: a track or an alias. The dictionary specification provides no convenient way to say "a track or an alias, either singly or a list" by means of four-letter codes; so iTunes's developers have effectively left the truth to be discovered by experimentation.
Enumerations
An enumeration is a list of four-letter codes. It is treated as a class, it has a four-letter code identifying it, and it is used as a value