Operators and Reference Forms
An operator is a
symbol or token that is used with values or variables in an
AppleScript expression. An example is the well-worn expression 2 + 2
= 4 (if you just dropped this expression into a Script Editor window,
it would return a boolean
value of
true
). The operators in this expression are
“+” and
“=”. AppleScript has most of the
operators that you would expect a scripting language to make
available to the programmer. AppleScript also allows the scripter to
use very readable English expressions for operators, such as:
if 5 is greater than 3 and 6 equals 6 then set bool to true
The principal symbolic operators are demonstrated in Example 1-10. All operators, including the English forms, are described in Chapter 4.
(* & concatenates one string to another, or combines two or more lists or records *) set twoPhrases to "One phrase " & "connected to another phrase." (* the following code returns {"a string inside of a list", "added at the end of a sentence."} *) set twoLists to {"a string inside of a list"} & {"added at the end of a sentence."} (* & also combines two records to make one record. *) set twoRecs to {firstn:"Amanda"} & {secondn:"Smith"} (* parentheses and Math operators do what you would expect them to *) set int to (5 * 6) - 8 -- returns 22 (*If you use / or ÷ the result is always a real data type. If you use div the result is always an integer *) set n1 to 50 / 26 -- returns 1.923076923077 set n2 to 50 ...
Get AppleScript in a Nutshell 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.