Language Guide
CHAPTER 2
Overview of AppleScript
14 How Does AppleScript Work?
How Does AppleScript Work? 2
AppleScript works by sending messages, called Apple events, to applications.
When you write a script, you write one or more groups of instructions called
statements. When you run the script, the Script Editor sends these statements
to the AppleScript extension, which interprets the statements and sends Apple
events to the appropriate applications. Figure 2-1 shows the relationship
between the Script Editor, the AppleScript extension, and the application.
The parts that you use—the Script Editor and the application—are shown to
the left of the dotted line in Figure 2-1. The parts that work behind the scenes—
the AppleScript extension and Apple events—are shown to the right of the
dotted line.
Applications respond to Apple events by performing actions, such as changing
a text style, getting a value, or opening a document. Applications can also
send Apple events back to the AppleScript extension to report results. The
AppleScript extension sends the final results to the Script Editor, where they
are displayed in the result window.
When you write scripts, you needn’t be concerned about Apple events or the
AppleScript extension. All you need to know is how to use the AppleScript
language to request the actions or results that you want.
Statements 2
Every script is a series of statements. Statements are structures similar to
sentences in human languages that contain instructions for AppleScript to
perform. When AppleScript runs a script, it reads the statements in order and
carries out their instructions. Some statements cause AppleScript to skip or
repeat certain instructions or change the way it performs certain tasks. These
statements, which are described in Chapter 7, are called control statements.