DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 17. Constants

This chapter catalogues the constants of the AppleScript language. A constant is a reserved word representing a value. You cannot set the value of a constant; if you try, you'll get a compile-time error, "Access not allowed." You cannot create a variable whose name is that of a constant; if you try, you'll get a compile-time error, "Expected variable name or property but found application constant or consideration." The datatype (class) of a constant is usually constant; but as we shall see, some of them are a class instead.

The fixed value of a constant will appear to you as the name of the constant. For example, the value of yes is yes; it cannot be reduced to any other form. But a constant is meaningful to AppleScript behind the scenes. Also, a constant can be coerced to a string.

Constants are often implemented as enumerations, meaning a set of values any of which may occupy a certain syntactic slot. For example, the replacing clause of a store script command (Section 9.6) may consist of any of the constants yes, no, or ask. Nothing stops you from supplying some other value, in which case it is up to the target to decide how it wants to respond. If you say replacing 42 in a store script command, the script will compile and run. If you try to set a date's weekday to yes, the script will compile but not run.

Applications are free to extend AppleScript's vocabulary by implementing constants of their own. For example, GraphicConverter can save an image file in many formats, and it needs a way to let you specify a format; it does this with some four dozen constants, such as PICT, TIFF, GIF, BMP, JPEG, and so forth. An application's dictionary will show you the constants that can be used in any connection with any command—though it probably won't tell you what they mean. See Section 19.3.1.

    [ Team LiB ] Previous Section Next Section