Chapter 17. Constants

A constant in AppleScript is a term that functions as a value. It isn't a variable, which is a name that has a value. A constant is a value. 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 (though a constant can be coerced to a string). You can use it as a value, but that's about all you can do with it. 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.

Behind the scenes, many constants are implemented as enumerations, meaning a set of fixed values (called enumerators), any of which may occupy a certain syntactic slot. For example, the replacing clause of the store script command (see "Compiled Script Files as Script Objects" in Chapter 8) may consist of any of the constants yes, no, or ask. Nothing stops you, however, 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 ...

Get AppleScript: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.