What causes a script to run? It might be that you deliberately run ityou press the Run button in a script editor application, for example, or you choose the script from the menu of a script runner environment. However, there is a whole class of situations where your script just sits there patiently and eventually some other process comes along and runs it, with no direct intervention or action on your part. I call this sort of milieu an automatic location (see Chapter 2). In an automatic location, AppleScript takes a passive instead of an active part. Instead of you personally setting a chain of events in motion, AppleScript operates in response to other events or activities taking place on your computer: someone inserts an audio CD, someone moves a file into a certain folder, a certain web page request appears at your server, a certain time of day arrives, the computer wakes from sleep, a certain hard drive is mounted, the telephone rings.
There are a number of distinct automatic locations built into Tiger, and there are many varieties of circumstance in which third-party applications may trigger your scripts. A complete compendium of the ways in which scripts can be triggered automatically would be impossible, so the chief purpose of this chapter is to awaken you to the range of possibilities. You may be surprised by the sorts of role AppleScript can play on your computer.
Preparing a script to operate in an automatic location is different from simply writing a script and running it. The reason is that you're not in charge. Some other process isthe process that will actually call your scriptand you must know and obey the strictures imposed by that process. In general, you'll need to know two things:
Finding out all of this is up to you, and will usually involve reading some sort of documentation. You are making a highly specific prearrangement with the triggering process, in accordance with a kind of contract; you must know the terms of that contract and abide by them, or things won't work.