Airfoil automation script

Playing audio in the living room with no fuss

I have an old iPhone connected to my home stereo. On this I have installed Airfoil speakers to be able to stream sound to my stereo wirelessly from anywhere in the apartment.

It is quite the nuisance to open Airfoil, select the program, select the living room speakers and if playing video making sure its sound is being output 2 seconds in advance to achieve audio sync.
Wouldn’t it be nice to just launch a script that does everything for you? It would need to be flexible to account for all different applications I might want to connect.
I decided to make a backbone library with common functions and then add a front end script for each application that might want to connect.

For me these app were:

  • Spotify
  • VLC
  • XBMC
  • iTunes
  • Chrome
  • Safari
  • MPlayerX

Airfoil library

Contains functionality to open and select target and source.

Airfoil Library

Click to view as PDF

Please do comment if you spot something that can be made better/more fool proof.
This works every time on my machine, this might not be so on all systems.


When connecting an application that handles video there is a need to make sure that audio is ahead by 2 seconds since there is a 2 second buffer delay built into Airfoil.
This is, for me, done when hooking up VLC or MPlayerX. XBMC is preconfigured to always delay -2 seconds. This is how I did that for VLC.

Click to view as PDF.

After starting the movie I launch this script, in my case with the best tool in the world i.e Quicksilver. It connects to all my available speakers and activates VLC. After that it sends the keystroke “f” to VLC 40 times in order to make the audio delay -2 seconds.
Thoughts on this is appreciated, especially the first two lines. That could be prettier.

The library now also contains routines to connect to password protected speakers this is reflected in the PDF of the library above.

Here it is at work. Quick, painless.

It gets to be even more of a time saver in MPlayerX where I can’t use keyboard to introduce the delay because I use a Swedish keyboard layout.
I would then have to go through menus 20 times… not fun! With the script… it clicks the menues the 20 times needed in about 1 second. Ahhhh….

Tagged , , , ,

One thought on “Airfoil automation script

  1. iTunes on macbook + airfoil + windows desktop + 5.1 speakers + airfoil speakers + air remote + ipad = awesome wireless media playback

Rip this hack a new one...

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: