AppleScript_ The Definitive Guide - Matt Neuburg [28]
}
}
}
------oo end of event oo------
Once more you can see the characteristic parts of an Apple event. This event is called core\getd; it has one parameter, the direct object designated by ----; and that direct object is an object specifier comprising the standard form, want, seld, and from.
What All This Has to Do with AppleScript
A raw Apple event in AEPrint or AEDebug format isn't impossible to read, but it isn't exactly easy either. Constructing one is even harder. Raw Apple events are meant primarily for computers, not for humans, to construct and to read. But now look at this:
move item 1 of (every message of incoming mail ¬
whose subject begins with "applescript") ¬
to end of mailbox "appleScript"
That is the very same Apple event from Example 3-1, but this time it's expressed in an English-like form. It's quite legible, and you can probably imagine constructing something like this for yourself. I certainly hope you can imagine it, because that's what this book is all about. That code is AppleScript.
Now you understand why AppleScript exists. AppleScript is a programming language whose chief purpose is to allow Apple events to be constructed and presented in an English-like form that is fairly intuitive and accessible to a human being. Thanks to AppleScript, you can take advantage of the power of Apple events, constructing and sending them for yourself.
The Open Scripting Architecture
When System 7 was being created, along with Apple events and many other new technologies, it was already Apple's plan to create a language, AppleScript, that would give end users access to the power of Apple events. But, much to the disappointment of users and developers, there wasn't time to create AppleScript before the release of System 7 in mid-1991, and the bulk of the work was postponed until 1992-1993.
One of the conundrums facing the founders of AppleScript at this time was the architectural question of where the language should live. They could have made AppleScript the internal scripting language of a single application, like HyperCard's HyperTalk , but this would mean that the user would run AppleScript code entirely from within this one application, which was unacceptable. AppleScript needed to be available everywhere, and thus would somehow have to be part of the system. But what part? There was no good place, so a new one was created: the resulting structure is the Open Scripting Architecture (OSA).
Components
Under the OSA, a scripting language is implemented by a something called a component . (Components were not invented specially for the OSA; they existed already in connection with QuickTime.) Think of a component as a piece of self-contained functionality made available at system level so that any program can hook up to it and use it. One thing that's special about components is that they can be installed and uninstalled dynamically. So an OSA-savvy program doesn't necessarily think in terms of any particular scripting language; it asks the system—in particular, the Component Manager —what scripting languages are presently installed, and if it wants to use one, the Component Manager provides access to it.
Because components are installed dynamically, this installation must actually take place while the computer is running. AppleScript is installed as the computer starts up and simply left in place, so that it's always available. You may recall that under Mac OS 9 there was an extension called AppleScript (in the Extensions folder of the system Folder). Its job was to install AppleScript as a component under the OSA as the computer started up. On Mac OS X, the same function is performed by a file called AppleScript.component, which is in /System/Library/Components; this type of file is called a component file.
One nice consequence of this architecture is that Apple can easily release upgrades to AppleScript, and the user can easily install them, with no effect on any other part of the system. AppleScript itself has a version number, which refers to the version number