Airfoil & iTunes Control

Posted on
Sat Nov 29, 2014 2:29 pm
OnnoH offline
Posts: 26
Joined: Nov 05, 2014
Location: The Netherlands

Airfoil & iTunes Control

I'd like to share a piece of Indigo Python code with you.

I have several Airplay devices around the house and started to use Airfoil to activate them after they're turned on. Sending a play command to iTunes works fine. If already playing the command is simply ignored. Pausing however should only occur if there's no other device still active. I came up with the following server side script in an action group:

Code: Select all
indigo.server.log("Action Group: Pause iTunes")

noPlaying = 0
connectedValue = "connected"
airfoilName = "Airfoil"
libraryName = "My Library"

itunesPlugin = indigo.server.getPlugin("com.perceptiveautomation.indigoplugin.itunes")
if itunesPlugin.isEnabled():

   folderId = indigo.variables.folders[airfoilName].id
   libraryId = indigo.devices[libraryName].id

   for var in indigo.variables:
      if var.folderId == folderId and var.value == connectedValue:
         noPlaying += 1
      
   if noPlaying > 1:
      indigo.server.log("Still playing. Let it be!")
   else:
      indigo.server.log("All quiet. Stop the music!")
      itunesPlugin.executeAction("pause", deviceId = libraryId)
else:
   indigo.server.log("No iTunes! What am I doing here?")

It seems to get the job done. What do you think? Any pointers? Am I missing something? As I'm always on the lookout to improve, comments are appreciated :wink:

Posted on
Wed Dec 10, 2014 3:44 pm
OnnoH offline
Posts: 26
Joined: Nov 05, 2014
Location: The Netherlands

Re: Airfoil & iTunes Control

Expanding (and renaming) my own post :)

Googled for an Airfoil/iTunes/Airplay issue and came across this thread http://forums.indigodomo.com/viewtopic.php?f=18&t=9100&p=65182&hilit=airplay#p65182

Sometimes Airfoil complains it cannot connect to a speaker, because it's in use. Very frustrating if this happens when the bedroom amplifier, scheduled to wake us up with lovely iTunes music, stays quiet :x

It seems that either my Apple TV connected to an Onkyo TX-NR616 or Denon Amplifier DRA-N5 (the wake up caller), claim possession of the Airplay setting in iTunes. This is maybe what's causing Airfoil failing to connect to that particular speaker.

Therefore I put the following AppleScript in an Action Group executed in other Action Groups.

Code: Select all
tell application "iTunes"
   set current AirPlay devices to AirPlay device "Computer"
end tell
Hopefully this will result in a reliable alarm clock 8)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests