DekGenius.com
[ Team LiB ] Previous Section Next Section

Chapter 9. Script Objects

A script object is a script within a script. In fact, a script really is a script object, but it also has a special status as the top-level script object—the script object that contains all others. A script object is defined using a block of code that starts with the keyword vertical barsscript, with syntax of this sort:

script scriptName
        -- commands within the script object
end script

When typing a script definition, don't bother to type the full phrase end script in the end line. Just type end for that line; the compiler will fill in the word script.


A script object may be defined anywhere—at top level, within a script object, or within a handler. The mere presence of a script object definition does not itself cause execution of any code within the script object. A script object's code is run only on demand. (Later sections of this chapter, such as Section 9.2 and Section 9.3, discuss how to make such a demand.)

Like a script, a script object may contain script properties, handlers, script objects, and code. A script object is a device for organization of code and data. Related handlers, script objects, and variables can be packaged in a single self-contained script object. Also, a compiled script file can be accessed as a script object by a running script; thus a script object can function as a library of commonly needed code, or as persistent storage for variable values.

Together with variables and handlers, script objects complete a script's "map of the world." Handlers and script objects are AppleScript's regions of scope. Global variables, handlers, and script objects are the three types of persistent top-level attribute of a script (or a script object). Variables, handlers, script objects, and code constitute the entire structure of a script.

    [ Team LiB ] Previous Section Next Section