Scripting Additions and Speed
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 Section 5.5).
Just how quickly a scripting addition is called, though, depends upon
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 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, the way this works is that the application is sent the Apple event denoting a scripting addition command and can’t deal with it; the message is then 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, it must go through an extra step. If you use a scripting addition command outside of any tell ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access