Chapter 21. Scripting Additions
A
scripting addition
(or
osax
) is a compiled code fragment, typically written in a language such as C, that extends the AppleScript language (see "Scripting Addition" in Chapter 3). A scripting addition has a dictionary, but it can't be
A scripting addition can define events (commands), records (pseudo-classes), and coercions. Generally speaking, a scripting addition can fulfill two purposes:
The default Tiger installation includes one scripting addition that adds to AppleScript's powersthe StandardAdditions osax. Many of the commands that it implements are so fundamental that this book treats them as part of the
Writing a scripting addition is beyond the scope of this book. If you're interested, Appendix C lists some resources that may
For some tips about speed when accessing a scripting addition command, see "Scripting Additions" in Chapter 22. |
21.1. Pros and Cons of Scripting Additions
A scripting addition implements functionality along with terminology for accessing it. So does a scriptable application. So why use a scripting addition rather than a scriptable application? There are clearly some things that scripting additions do better than scriptable applications. An application must be running in order to be targeted; if it isn't running, it must be found, which may require
On the other hand, in some ways scripting additions are clearly a Bad Thing. There are some considerations of memory management, though these are too technical to describe here. A scripting addition is inconvenient, as in order to be available to a script, it must be not merely present on the user's machine (like a scriptable application) but installed in a particular location. Scripting additions can define coercions, but these cannot be documented in the dictionary. Finally, scripting additions invade the global AppleScript namespace, in ways that can be confusing and frustrating. A scripting addition may conflict with terminology the programmer would like to use; if a scripting addition was present when a script was compiled and absent when the script is run, the script may break, and the cause may be difficult to track down. (See Chapter 20 for examples and further discussion.)
For these reasons and others, Apple actively discourages, by word and deed, the
The deeds consist of Apple's own steady retreat from the use of scripting additions, replacing them with scriptable applications (which may be faceless background applications). On Mac OS 9, of the nine files present by default in the Scripting Additions folder, five are applications; under Mac OS X, of the seven files present in /System/Library/ScriptingAdditions , five are applications. (There's no particular reason why such an application should live in the ScriptingAdditions folder; it must still be launched and targeted like any other application. So the placement of these applications in this folder is a way of ensuring their presence while suggesting that they fulfill a utility function similar to a scripting addition.)
Nonetheless, scripting additions have a venerable history and don't show signs of going away
|