iTunes Airplay Selection

heya,
I’m new to the forum and applescript, but i have some experience with windows shell scripting and sql. Now on to what i’m looking to do.

I’m trying to write an apple script that wil;
fire up itunes
play a playlist
adjust the volume
select 3 specific airplay speakers

No i’m all good up to the point where i try to figure out the window name and ui element to click for the “multiple” radio button off the airplay screen (button 9). Tried UI browse to help lead me in the right direction, but i think i have the window name wrong. Any help would be appreciated. I’m running itunes 11.


tell application "iTunes"
	activate
end tell

tell application "iTunes"
	play playlist "wfpl"
end tell
tell application "System Events"
	tell process "iTunes"
		click button 9 of window "iTunes"
		delay 0.5

		-- Need to figure out how to activate the Multiple radio button here --

	end tell
end tell

tell application "iTunes"
	set the sound volume to 30
end tell


appreciate just getting past this one hurdle so i can ove on to the next!

Model: mac mini 2010
AppleScript: 2.2.4
Browser: Safari 537.31
Operating System: Mac OS X (10.8)

Hi shaneakus,

I don’t have an airplay speaker, so don’t know where you’re trying to click, but here’s the process I use.

First, I might start with something like this:


tell application "iTunes"
	activate
	play playlist "Library"
end tell
tell application "System Events"
	tell process "iTunes"
		every UI element
	end tell
end tell

result: {window “iTunes” of application process “iTunes” of application “System Events”, window “Equalizer” of application process “iTunes” of application “System Events”, menu bar 1 of application process “iTunes” of application “System Events”}

This gives you a list of ui elements of the iTunes application. Now suppose you want the ui elements of the iTunes window.


tell application "iTunes"
	activate
	play playlist "Library"
end tell
tell application "System Events"
	tell process "iTunes"
		tell window "iTunes"
			every UI element
		end tell
	end tell
end tell

result: {button 1 of window “iTunes” of application process “iTunes” of application “System Events”, button 2 of window “iTunes” of application process “iTunes” of application “System Events”, button 3 of window “iTunes” of application process “iTunes” of application “System Events”, button 4 of window “iTunes” of application process “iTunes” of application “System Events”, button 5 of window “iTunes” of application process “iTunes” of application “System Events”, button 6 of window “iTunes” of application process “iTunes” of application “System Events”, button 7 of window “iTunes” of application process “iTunes” of application “System Events”, button 8 of window “iTunes” of application process “iTunes” of application “System Events”, slider 1 of window “iTunes” of application process “iTunes” of application “System Events”, scroll area 1 of window “iTunes” of application process “iTunes” of application “System Events”, text field 1 of window “iTunes” of application process “iTunes” of application “System Events”, button “1114 songs, 2.8 days, 8.99 GB” of window “iTunes” of application process “iTunes” of application “System Events”, splitter group 1 of window “iTunes” of application process “iTunes” of application “System Events”}

Then you find which one of these ui elements you want next. You keep going until you find the right ui element string of references for your tell blocks. This can be tedious work because oftentimes, the element you want to get to is placed in another ui element. Sometimes you need to try every branch.

Hope this helps. You can use the Accessibility Inspector in xCode to guide you in what kind of ui element you should be looking for.

gl,

Model: MBP
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Thanks for the response, button 9 brings up the screen that i want, but i’m unable to manipulate it past that point. After some research i think it’s an issue with the new popover layers that apple’s been using with apps like itunes and safari. There’s no real way to access the elements contained in those layers.

i did however modify the script to reflect your suggestion:


tell application "iTunes"
	activate
end tell

tell application "iTunes"
	activate
end tell

tell application "iTunes"
	play playlist "wfpl"
end tell
tell application "System Events"
	tell process "iTunes"
		click button 9 of window "iTunes"
		delay 0.5
		tell application "System Events"
			tell process "iTunes"
				every UI element
				-- Need to figure out how to activate the Multiple radio button here --
			end tell
		end tell
	end tell
end tell

I ran the every ui element argument once the button 9 popover layer was displayed, this is the result:


{window "iTunes" of application process "iTunes" of application "System Events", menu bar 1 of application process "iTunes" of application "System Events"}

Try this:


tell application "iTunes"
	activate
	play playlist "wfpl"
end tell
tell application "System Events"
	tell process "iTunes"
		tell window "iTunes"
			click button 9
			delay 1
			every UI element
			-- Need to figure out how to activate the Multiple radio button here --
		end tell
	end tell
end tell

result: ?

gl,

Editted: often, buttons are in a group or something like that. Also, instead of click you can try select maybe or press. It has been a while since I did this.

If that didn’t work, try this:


tell application "iTunes"
	activate
	play playlist "wfpl"
end tell
tell application "System Events"
	tell process "iTunes"
		tell window "iTunes"
			click button 9
			delay 1
			-- Need to figure out how to activate the Multiple radio button here --
		end tell
		every UI element
	end tell
end tell

Clicking the button might have created a new window.

gl,