Your browser (Internet Explorer 7 or lower) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browsergoogle00
.

X

Navigate / search

Control Airplay/Airtunes in iTunes 10.1 with Applescript

My previously published Applescript to control iTunes Airplay/Airtunes speakers was broken recently when Apple released iTunes version 10.1. Apple made a few minor tweaks to the speaker control elements, which is to be expected since one of the key features in the 10.1 release is related to Airplay support.

I have re-created the script, which behaves almost identically to previous versions. This one contains a little bit more error checking for dealing with various iTunes states. I’ve also included more code comments than previous versions, which should help people modify it to their own needs.

Here is the code, Working as of December 3rd on iTunes 10.1.

– Remember to turn on access for assistive devices.
– Working as of December 2010 with iTunes 10.1 only.
– See http://fall-line.com for iTunes 9 and 10.0 version.
– Define the playlist we are going to work with. Just Change this to the name of whatever iTunes playlist you want to be played.
set MyPlaylist to “Dinner Time”
– Check to see if GUI scripting is enabled on this machine, else prompt the user to turn it on.
on GUIScripting_status()
– check to see if assistive devices is enabled
tell application “System Events”
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application “System Preferences”
activate
set current pane to pane id “com.apple.preference.universalaccess”
display dialog “This script utilizes the built-in Graphic User Interface Scripting architecture of Mac OS x which is currently disabled.” & return & return & “You can activate GUI Scripting by selecting the checkbox \”Enable access for assistive devices\” in the Universal Access preference pane.” with icon 1 buttons {“Cancel”} default button 1
end tell
end if
end GUIScripting_status
–Open iTunes, even if it isn’t running
activateapplication “iTunes”
delay 1
tell application “System Events”

– First, we have to close the Multiple Speakears window if it is still open, for some reason this is now necessary to refresh speaker states in 10.1.
tell window “Multiple Speakers” of application process “iTunes” of application “System Events”
try – don’t fail if the window isn’t open
activate
clickbutton 3 – Red X button
end try
end tell

tell application “iTunes”
set visible of front browser window to true–Make sure the main window is visible (necessary for the remaining UI code)
set the view of the front browser window to playlistMyPlaylist–Display the playlist we are about to stary playing, just nice to have.
end tell

delay 1
tell window “iTunes” of application process “iTunes”

click button 8 of window “iTunes” of application process “iTunes” of application “System Events” –Press the iTunes Speaker Button
key code 125 using {command down} – this is essentially hitting page down (command + down arrow), to select the last item in the menu
delay 0.1
keystrokereturn–hit enter

– We now have a new Multiple Speakears window to work with
tell window “Multiple Speakers” of application process “iTunes” of application “System Events”
activate

–If you want to turn the Master volume up to full, uncomment the next line.
– click button 2

tell table 1 of scroll area 1
activate

repeat with i from 1 to (count of every row) – Itterate through each row, looking for the criteria below

set rowcount to count of rows
if rowcount > 0 then

tell group 1 of row i
activate

if description of checkbox 1 as string = “Computer” and value of checkbox 1 = 0 then
set value of checkbox 1 to 1
delay 1
end if
if description of checkbox 1 as string = “AAA” and value of checkbox 1 = 0 then
set value of checkbox 1 to 1
delay 1
end if

end tell

end if
end repeat
end tell

end tell

end tell
end tell
– Finally, shuffle up and play the Playlist
tell application “iTunes”
set shuffle of playlist MyPlaylist to 0
set shuffle of playlist MyPlaylist to 1
set shuffle of playlist MyPlaylist to 0
set shuffle of playlist MyPlaylist to 1
playplaylistMyPlaylist
end tell

Leave a comment

name

email (not published)

website