AppleScript_ The Definitive Guide - Matt Neuburg [33]
The term "script" has thus ended up as an acceptable synonym for the politically incorrect "program." Ostensibly, you do not program with AppleScript; you script with it. What you write are not programs; they're scripts. You're not a programmer; you're a scripter. This, I feel, is just silly. AppleScript is a programming language (and, I happen to think, not a particularly easy one). You are a programmer, and you will write programs with AppleScript.
Script as Script Object
Many AppleScript programs that you write or read will contain the term script used to demarcate part of their code. Here's an example:
script myScript
display dialog "Hello from " & (get my name) & "!"
end script
run myScript — dialog says:Hello from myScript!
The first three lines are a block of code starting with the word script. Such a section of code is often called a script object.
In fact, it turns out that an AppleScript program as a whole is itself a script object. This may sound confusing, but in fact it's quite a cool and sophisticated aspect of AppleScript. Thus it is reasonable and rigorously correct to speak of an AppleScript program as a whole as a script, not as a way of avoiding the fact that it is a program, but as a way of expressing its ontological status within the world of AppleScript. As you'll learn later, a script as a whole and a script object within a script have exactly the same ontological status. The script-as-a-whole does have some special features of its own, because it is the ultimate container of any other script objects; it is the top-level script object. But it is not different in kind from script objects that it may contain. (We'll fully explore the details of script objects later in the book, especially in Chapter 8.)
Script as Scripting Component Operand
The term "script" also refers in a completely technical and rigorous sense to a unit of operation between an application that asks for some AppleScript code to be compiled or executed and the scripting component that does the actual work. When such a program sends the scripting component a bunch of text for compilation, as in Figure 3-2, that bunch of text is assigned an identifying number. This number points to the code that is being remembered by the scripting component, and is called its script ID. It is by this arrangement that the application and the scripting component can continue to talk about the code while it persists over time, as described earlier in this chapter ("Maintenance of State"). The code itself, the thing being remembered by the scripting component, is thus technically a script, because that's what the scripting component itself calls it. A script is a kind of entity that the scripting component holds on to and can perform various operations on, such as compiling it or executing it.
Script as File
The individual code file is an important and meaningful unit in AppleScript. Unlike some programming environments, where multiple files are assembled through a "make" or some other build process into a separate object file embodying the complete program, with AppleScript the individual file is the complete program. An AppleScript program and the file containing it are thus coterminous. But, as we have just seen, an AppleScript program is a script, because it is a script object. In fact, it will turn out that any script object can be saved as a file (see "Compiled Script Files as Script Objects" in Chapter 8). Just the other way around, any saved compiled script file can be handed to an AppleScript scripting component (as a script) and executed. There is thus a natural and meaningful correspondence between scripts and files, and it makes sense to speak of the file in