Scripting via AppleScript
Beginning with version 2.0, Airfoil supports a full AppleScripting suite. Just about anything you can do with the graphical user interface, you can now also script. The following is a brief overview of the object model that Airfoil exposes. For a complete reference, see Airfoil's Scripting Dictionary in Script Editor. If you are new to AppleScript, we recommend you pick up a copy of AppleScript : The Definitive Guide by Matt Neuburg, before proceeding.
Accessing and Controlling Speakers
The primary object in Airfoil, is the speaker. It represents an Aiport Express on the network, which you can start and stop and set the volume of. Before that though, we need to actually retrieve a speaker instance on which to operate on. Airfoil maintains a list of avaliable speakers on the application object.
Once we have a speaker, we can set it's volume, or connect/disconnect from it. Here's an example script that toggles the connection to the first speaker found:
All About Audio Sources
Beyond controlling the speakers, Airfoil's AppleScript dictionary gives you complete control over the audio source used. The five types of audio sources are all represented: application source, widget source, device source, radio source, and system source.
Application sources represent an application on the hard disk. To target an application source, you create a new instance, set it's application file property to the full POSIX path of an application, and then set the application's current audio source to it:
Device sources represent hardware audio devices such as microphones or line-in ports. Airfoil maintains a list of device sources from which you can select, and then target. The following example script displays a "choose from list" dialog with every audio device in it:
radio sources represent hardware AM/FM radios such as the RadioSHARK or D-Link DBR-100. Like device sources, Airfoil maintains a list of connected radio devices that you can choose from. The radio device can be tuned by using the band and frequency properties:
If you have the Soundflower extra installed, you can use the system sources to transmit all audio from the computer. Naturally, there is only ever one System Audio source:
Putting it all Together
Finally, heres a complete script showing a typical usage of Airfoil. We find a target application, create a new application source for it, and then transmit it to a speaker.