Attachability/Recordability

If an application is either attachable or recordable (or both), it is considered a near paragon of scriptability. Attachable means that you can create a script and then attach it to a program, so that the script is added to the program’s internal menus. Applications usually implement attachability with Mac OS 9 by providing a folder for scripts and a menu item on their menubars that lists these available scripts. Figure 1-2 shows a menubar that contains a list of attached scripts for the BBEdit text editor.

Attached scripts in BBEdit

Attached scripts will often run much faster than scripts that run as self-contained applets even if the script doesn’t have anything to do with the application it is attached to (i.e., the script never sends Apple events to the host application). For example, I have an AppleScript that reads large web logs (more than 1 MB in size) looking for and recording for later display certain file paths. When attached to BBEdit 5.1, the script runs about six times as fast as it does when run as an applet outside of BBEdit (40 seconds as opposed to about 240 seconds). Try it with some of your own scripts.

A few applications allow themselves to be recorded by Script Editor, which is a great way to get started with scripting them. To do this, open Script Editor and click its Record button (see Chapter 2). You then activate an application and perform the actions that you are trying to record, or simply go in and manipulate its menus to see what happens. Once you click Stop in Script Editor, the Script Editor window will display the AppleScript source code representing the recorded actions. If the application is not recordable, the Script Editor window will be empty after you click Stop. Otherwise, you can then save the AppleScript as a macro that you can use and/or modify in the future. The Finder, BBEdit, and Microsoft Word are examples of recordable applications.