B.1. Operators

The following table summarizes the various AppleScript operators. These operators are listed in order of decreasing precedence. Operators grouped together have the same precedence.

OperatorOperatorAssociativity
Unary minus
+Unary plus 
^ExponentiationRight to left
*MultiplicationLeft to right
/Division 
div  
 Integer division 
modModulus 
+AdditionLeft to right
Subtraction 
&ConcatenationLeft to right
asCoercionLeft to right
<, ≤ >, ≥Relational
=, ≠Equality / Inequality
notLogical negation
andLogical ANDLeft to right
orLogical ORLeft to right

As an example of how to use the table, consider the expression

b < c + d * e

The multiplication operator has higher precedence than both the addition and less-than operators because it appears above both of these in the table. Similarly, the multiplication operator has higher precedence than the addition operator because the former appears above the latter in the table. Therefore, this expression is evaluated as

b <  (c +  (d * e))

Now consider the following expression:

b mod c * d

Because the modulus and multiplication operators appear in the same grouping in the table, they have the same precedence. The associativity property then comes into play. For these operators, the associativ¬ity is listed in the table as left to right, indicating that the expression would be evaluated as

(b mod c)  * d

When using the logical and operator, you are guaranteed that the second operand will not be evalu¬ated if the first is false; and in the case of ...

Get Beginning AppleScript® 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.