AppleScript_ The Definitive Guide - Matt Neuburg [120]
Script objects, handlers, and references are not dealt with in this chapter (see respectively Chapters 8, 9, and 12). The details of coercion, the conversion of certain values from one datatype to another, will be explained in Chapters 14 and 15.
Application
The application class is used mainly to specify a target. This, in effect, is the primary act of AppleScript programming. You specify a target so that you can send messages to it, and sending messages to an application is the purpose of AppleScript.
You specify an application using an object string specifier —the word application followed by a string representing the application's name or (colon-delimited) pathname. An abbreviation for application is app. For further details on how to target an application using an application specifier, see "Local Applications" in Chapter 23.
Machine
The machine class is used to form a machine specifier, which appears in conjunction with an application specifier to target an application running on another computer. See "Remote Applications" in Chapter 23 for further details.
Data
The data class represents raw data , a stream of bytes. It's a catch-all for situations when a value cannot be displayed in any other way. For example:
tell application "Finder"
activate
get (the clipboard)
end tell
-- {«class RECT»:«data RECT0000000000B40075»,¬picture:«data PICTFA480000000000B40075001102FF0C...»},
and so on for pages and pages
Here we see a record with two items; the value of each item (after the colon) is a data object. What was on the clipboard was a picture, and the Script Editor can't display it (though Script Debugger can), so it shows you the data as a sequence of hex bytes. Evidently what we have is a rectangle (probably the bounds of the picture) and a picture resource in PICT format.
It is also possible to form a data object yourself, by typing just the sort of thing you see here: the word data, a space, and then the resource type and the data, in guillemets (« »). However, this is an advanced technique and shouldn't arise much in real life (though an example of it appears later in this chapter).
Boolean
A boolean is a datatype consisting of exactly two possible values: true and false . The main use for a boolean is as a condition in a control statement, such as if or repeat while (see Chapter 19). It often appears also as a way of setting yes-or-no options in a command; for example, the choose file command (discussed in Chapter 21) lets you submit a boolean to indicate whether invisible files and folders should be displayed. Some common commands, such as exists, return a boolean. AppleScript has a number of operators that generate or combine booleans (listed in Chapter 15).
class of true -- boolean
class of (1 < 2) --boolean
Integer, Real, and Number
The integer and real datatypes are the numeric classes. Integers and reals are used for arithmetic calculation (Chapter 15 will discuss AppleScript's operators for this purpose); they are also used, of course, for communicating numeric values between your script and a target application.
class of 1 -- integer
class of 1.1 --real
A literal integer is a series of digits, possibly preceded by a minus sign. The maximum integer is 536870911, positive or negative. Any integer value outside this range is implicitly coerced to a real. This is a very strange limit—it's 229-1, two bits short of the four-byte standard—and I don't know the reason for it.
A literal real is a series of digits with a decimal point, possibly preceded by a minus sign. You may also use "scientific notation ": that's a number followed by small or capital e, possibly followed by a plus sign or a minus sign, followed by an integer. AppleScript might rewrite a scientific notation number for you, but