Language Guide
CHAPTER 7
Control Statements
190 If Statements
NOTES
If referenceToObject specifies an application on a remote computer, additional
conditions must be met. These conditions are described in “References to
Applications,” which begins on page 146.
If referenceToObject specifies an application on the same computer that is not
running, AppleScript launches the application.
If Statements 7
If statements allow you to define statements or groups of statements that are
executed only in specific circumstances. Each If statement contains one or more
Boolean expressions whose values can be either true or false. AppleScript
executes the statements contained in the If statement only if the value of the
Boolean expression is true.
If statements are also called conditional statements. Boolean expressions in If
statements are also called tests.
The following example uses an If statement to control whether or not a
particular dialog box is displayed:
if dependents > 2 then
display dialog "You might need to file an extra form"
end if
The If statement contains the Boolean expression dependents > 2. If the
value of the Boolean expression is true, the Display Dialog command is
executed. If the value of the Boolean expression is false, the Display Dialog
command is not executed. (Display Dialog is a scripting addition command.
For more information about the way it works, see the AppleScript Scripting
Additions Guide.)
If statements can contain multiple tests. For example, the following statement
contains three tests.
if ( x > y ) then
set myMessage to " is greater than "
else if ( x < y ) then
set myMessage to " is less than "