Digital Hub Scripting

You probably have your computer set up so that when you insert a music CD, the application iTunes runs. This is one example of a general phenomenon called digital hub scripting: when a DVD, or a CD that doesn’t consist of ordinary files, is inserted into your computer, the System can react by sending an Apple event to a designated application. You can interpose your own code in this process: instead of iTunes, when an event like this occurs, an applet of your choice is notified, and can react in any desired manner.

In the CDs & DVDs pane of System Preferences are the settings that determine how the System reacts to a disk-insertion event. You can determine what application should be notified when the disk is inserted. If this application is an applet, it should be prepared to receive an Apple event corresponding to what sort of disk was inserted. The terminology for these Apple events is defined in the dictionary of the Digital Hub Scripting scripting addition. (Therefore the parameter does not need to appear in parentheses at the start of the definition.)

Let’s say we want to take charge of what happens when a music CD is inserted. We’ll create an applet called musicListener. In the CDs & DVDs pane of System Preferences, we use the Open Other Application menu item to set musicListener as the target application to respond when a music CD being inserted. In musicListener, the music CD appeared handler will be called when a music CD is inserted.

To illustrate, ...

Get AppleScript: The Definitive Guide 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.