Loading Scripting Additions

A scripting addition is not targeted; it is loaded. In particular, in order to be seen and used by a script, a scripting addition must be loaded by the AppleScript scripting component instance that is going to compile or run that script (see Chapter 3). For that to happen, the scripting addition file must be physically installed in any of a specific set of locations at the time that the AppleScript component instance is summoned into existence. On Mac OS X, those locations are, in the first instance, the three /Library/ScriptAdditions directories—in /System, at the top level, and in the user directory. (On previous systems, there was one location, the Scripting Additions folder; this was originally in the Extensions folder but was moved into the System Folder starting in Mac OS 8.)

This architecture has historically caused headaches for script developers. If you wanted to write a script relying on a third-party scripting addition and distribute that script to others, you had to worry about how to guarantee that your end user had the right scripting addition in the right location by the time the script ran. Typically this involved social engineering. First you had to ascertain what scripting additions your script was calling. (Script Debugger is especially helpful here; it lists the scripting additions on which your script depends, even looking up any unresolved event codes on http://macscripter.net for you.) Then you had to distribute the required scripting ...

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.