0

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?

eecue
  • 1,023
  • 9
  • 6

4 Answers4

5

Airplay Device is now a scriptable object - no need for UI tricks.

e.g.

tell application "iTunes" to get name of AirPlay devices

tell application "iTunes" to set selected of AirPlay device "Master Bedroom" to true

rkam
  • 51
  • 1
  • 4
  • OH!!! This is so good! Add another line to tell application "iTunes" to set selected of AirPlay device "Computer" to false and you're set, if you want to switch iTunes from your Mac to your airplay speaker. So good! Thank you! – 2oh1 Apr 21 '17 at 06:30
1

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.

PPMcC
  • 26
  • 1
  • This is awesome, thanks. How can I tell if the item is already selected so that this script doesn't turn off speakers? – eecue Apr 10 '13 at 18:33
0

I don't have iTunes with me now, but the syntax to select the checkbox with System Events should be click checkbox "Multiple"

Michele Percich
  • 1,872
  • 2
  • 14
  • 20
0

Since iTunes is no longer a thing in 2022 on MacOS, you can do that via the Audio Output preferences of Audio MIDI Setup.

This post should be helpful: How to set the current audio device to airplay speaker in Apple Script?

Marceli Wac
  • 375
  • 3
  • 13