Scripting Additions

One of the main reasons for using scripting additions is speed. For repeated trigonometric calculations, for example, it is certainly going to be a lot faster to use a scripting addition, such as the Satimage osax, than to roll your own calculation (as disingenuously suggested at Apple's web site). Similarly, a scripting addition that implements transformations to a list, such as returning a list with a particular element deleted, is going to be faster than coding the same operation in AppleScript (see "LISP-likeness" in Chapter 4). Just how quickly a scripting addition is called, however, depends on how you call it.

The osax architecture is such that a scripting addition appears to be present "inside" whatever application is being targeted when the scripting addition command is called. This behavior is noticeable, and useful, when a scripting addition puts up some user interface. For example, if the display dialog command is called from within a tell block targeting the Finder, the dialog appears within the Finder; it's as if you'd given the Finder a new dialog.

Behind the scenes, though, this architecture involves a serious inefficiency. The application itself is sent the Apple event denoting a scripting addition command. Obviously the application can't deal with this Apple event, so at that point the message is sent on up to the realm of scripting additions as a kind of fallback. This means that when you use a scripting addition command while targeting an application, ...

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.