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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access