2.4. Automatic Location
An automatic location is much like a script runner. But there's a significant difference. A script runner finds compiled script files in a prearranged location and offers you an interface so that you can run them when you want to. An automatic location is a place where an application finds compiled script files and runs them automatically, with no intervention on your part. The application runs the script when it wants totypically in reponse to the occurrence of certain events or stimuli. This doesn't mean you've no involvement, though; you were involved when you arranged for the application to find this script in this location, or to look for it in response to this particular event or stimulus.
BBEdit is an example. I've mentioned (in the previous section, "Script Runner") that BBEdit will use a menu to let you run scripts it finds in a Scripts folder within ~/Library/Application Support/BBEdit/. BBEdit looks for two additional folders in that locationStartup Items and Shutdown Items. These are repositories for scripts that BBEdit will run automatically in response to being launched and being quit, respectively. Similarly, when you choose from any of BBEdit's built-in menus, BBEdit will run an appropriately named script located in the Menu Scripts folder. Now, all these scripts and folders did not come into existence by themselves; you put them there. But once you've done that, since these are automatic locations, BBEdit runs the scripts automatically when the appropriate events occur.
Email clients, such as Apple's Mail and Microsoft Entourage, have "rules," which are essentially filter actions to be applied to mail messages. The usual configuration is to have these rules applied automatically when new mail arrives. One of the things such a rule can do is to run an AppleScript file. Again, these applications do not spontaneously invent the rules or include AppleScript files in them; you do that. But once you've done it, the application turns to the AppleScript file automatically in response to the arrival of new mail. iCal, too, can run an AppleScript file when the alarm for an upcoming event is triggered.
There are also "folder actions ," a mechanism whereby a folder in the Finder can be set up to watch for when certain events occur within that folderthat folder's window is opened, closed, or moved, or something is put into or removed from that folderand can respond to those events by running an associated script.
Some applications use automatic locations as their life's blood. For example, Salling Clicker is all about running AppleScript files in response to your pressing the buttons on a mobile phone or PDA. And Ovolab Phlink is all about running AppleScript files in response to phone calls arriving on your phone line, identification of the caller ID, the caller pressing buttons on a touchtone phone, the caller hanging up, and so forth.
For fuller treatment of the various ways in which a script can be triggered automatically (including an example of a folder action), see Chapter 26.