DekGenius.com
Team LiB   Previous Section   Next Section

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 *)

Table 4-1. AppleScript Operators
&
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, does not equal, or is greater than. As a scripter, the choice is entirely up to you whether to use is less than or the < symbol, for instance. The latter two operators are synonyms and have the same meaning in code. Table 4-1 lists the operators that are covered in this chapter, but not all of the possible synonyms (e.g., is less than, comes before, is not greater than). The synonyms for each operator are listed in the Synonyms heading of the sections (described in alphabetical order in the remainder of this chapter) on each operator.

    Team LiB   Previous Section   Next Section