Language Guide
CHAPTER 3
Values
Coercing Values 69
If you provide a command parameter or operand of the wrong class, AppleScript
automatically coerces the operand or parameter to the expected class, if possible.
For example, when AppleScript executes this statement,
repeat ( word 2 of document "Big" of application
"Scriptable Text Editor") times
display dialog "Hello"
end repeat
it expects the number of times to be an integer. To coerce word 2 of
document "Big" of application "Scriptable Text Editor" to
an integer, AppleScript gets the value of word 2 of document "Big"
of application "Scriptable Text Editor"—a string—and then
coerces it to an integer, if possible.
Not all values can be coerced to all other classes of values. Figure 3-2 summarizes
the coercions that AppleScript supports. To use the figure, find the class of the
value to be coerced in the column at the left. Search across the table to the column
labeled with the class to which you want to coerce the value. If there is a square
at the intersection, then AppleScript supports the coercion.
Reference values are not included in the table because applications determine
whether the value of an object specified by a reference value can be coerced to a
desired class.
For more information about each coercion, see the corresponding value class
definitions in this chapter.
Note
When coercing strings to values of class Integer, Number,
or Real or vice versa, AppleScript uses the current settings
in the Numbers control panel for decimal and thousands
to determine what separators to use in the string.
When coercing strings to values of class date or vice versa,
AppleScript uses the current settings in the Date & Time
control panel for date and time format. ◆