Chapter 6. A Map of the World
Every AppleScript program is a script. This chapter describes the structure of a script. A script is composed of certain definite building blocks, and they go together in a certain way. The next several chapters will return to each of these building blocks individually and explain them in full detail, but first we need an introduction to the entire cast of characters that constitute a script. That's what this chapter is for. It provides the crucial overall map of a script's world, so that in our explorations during subsequent chapters you'll know where we're going and how the geography fits together.
Scope Blocks
Recall (from "Blocks" in Chapter 5) that a pretty-printed script displays its structure by means of indentation. Every set of indented lines is introduced by an on
line and terminated by a corresponding end
line. The whole thing is a block
. For example, this is a repeat block:
repeat 3 times display dialog "Howdy" end repeat
It turns out that two types of block are very special in AppleScript: a script object definition and a handler definition. They are special in many ways. These are the only blocks that function as what I'll call top-level entities in a script. They are not merely blocks; they are also variable definitions. There are special rules for where they occur in a script. Most obviously, they are the regions of scope in a script; for this reason, I call them the scope blocks.
Scope will be fully discussed in Chapter 10, but the ...
Get AppleScript: The Definitive Guide, 2nd Edition 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.