Search code examples
applescriptitunesairplay

AirPlay Speakers via AppleScript


I have had partial success getting Indigo to toggle Airplay devices on in iTunes 11, but I need some help. I am able to select and toggle on one speaker, but really I want to be able to select the multiple button and then toggle on all or some of my speakers. Here is what I have that works for one:

tell application "iTunes" to activate
tell application "System Events"
   tell window "iTunes" of process "iTunes"
      click (first UI element whose help is "Choose which speakers to use.")
      keystroke "Master Bedroom" & return
      --perform action "press" in radio button "Multiple" of window "iTunes"--
   end tell
end tell

So that code opens it up and highlights the Master Bedroom line, but it doesn't actually select the checkbox, I played around with the commented out line, but couldn't get it to work. Thoughts?


Solution

  • This does it for me:

    tell application "iTunes" to activate
    tell application "System Events"
        tell window "iTunes" of process "iTunes"
            click (first UI element whose help is "Choose which speakers to use.")
            keystroke "Kitchen" & return
            delay 1
            key code 76
        end tell
    end tell
    

    I have been struggling with this ever since 11 came out. key code 76 is the enter key.