Chapter 4. Operators
Operators
are symbols that programmers use to perform operations in AppleScript
code, such as in mathematical expressions or equality tests.
Operators (e.g., =, +,
-, *) are familiar to
programmers in other languages (such as Java and Perl), as well as
young math students. In the following AppleScript code fragment, the
* and the = characters are the
operators:
2 * 10 = 20
With the exception of parentheses,
AppleScript’s operators (listed in Table 4-1) are binary operators,
meaning that each operator takes an operand, such as a number,
variable, or expression, on either side of it. In the previous code
fragment, the 2 is the left-hand operand and the 10 is the right-hand
operand for the * operator. Operators can also be
used to test two expressions for equality or to combine two strings
into one string, as in these two code fragments:
Set eq to (56.5 >= 56) (* the eq variable is set to true; the >=
("greater than or equal to") operator is used to test two values for
equivalence *)
Set twostrings to ("two strings" & " are now one string.") (* using
the & string-concatenation operator *)
& |
As |
( ) |
Begins with |
* |
Contains |
+ |
Does not contain |
- |
Does not equal |
/ ÷ div |
Ends with |
< |
Is contained by |
<= ≤ |
Is not contained by |
= |
Mod |
> |
Not |
>= ≥ |
Or |
A reference to | |
And |
A distinguishing element of AppleScript is that its operators can be
either symbols, such as &,
=, +, or ≥ , or human-language
words such as equals,
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