Previous Page
Next Page

11.3. Class

Every value is of some fixed and definite type . I usually refer to this as its datatype , but the AppleScript term for speaking of a value's type is class . You can use the term class to inquire of any value what its datatype is:

class of 7 -- integer
class of "howdy" -- string
class of {"Mannie"} -- list
class of class of 1975 -- class

As the last line shows, even something's class is a value and therefore has to have a class, namely class.

Strictly speaking, the datatype of terms like integer and class is not really class but rather type class . It's as if every value has an attribute called class whose value is itself a type class. However, AppleScript will never tell you that the class of anything is type class. You may see a class referred to as type, though, in a dictionary or error message:

2 as boolean -- error: Can't make 2 into type boolean


You can assign a value of any class to any variable, but at a given moment a variable has only one value and that value has only one class (so it is customary to speak of a variable's class, meaning the class of the value it has at that moment).

It is the class of something that determines what messages can be sent to it and what attributes it has. For example, a list has a length because it is a list. I am guaranteed that I can ask any list for its length and get back a meaningful answer. I am also guaranteed that I can send the count message to any list and get back a meaningful response (the same as its length, actually).

The classes of many of the objects you'll be interested in when you're working with AppleScript will be classes defined by some particular scriptable application. This is unfortunate, because such classes are much harder to work with than, say, a list. A list is always a list, but two classes with the same name, defined by two different applications, might well be nothing like one another. The Finder has a folder class and Entourage has a folder class, but a Finder folder and an Entourage folder have virtually nothing in common; they have totally different sets of attributes. Indeed, both the Finder and Entourage themselves belong to the application class, but they have very little in common too. And when it comes to messages, things are even worse; the Finder knows very well what messages it is legal to send to one of its folders, but the Finder's dictionary does little or nothing to tell you what they are. There will be much more groaning about this in Chapter 20.


Previous Page
Next Page