Scripting New iTunes 11 - item of pop up button

Hi

I have this script:

tell application "iTunes" to activate
tell application "System Events"
	tell process "iTunes"
		tell pop up button 1 of window "iTunes"
			click
			delay 0.5
			set listofItems to get name of every menu item
			tell menu 1
				click menu item "TV Shows"
			end tell
			--keystroke "t"
			--delay 0.5
			--keystroke return
		end tell
	end tell
end tell

The pop up button is correctly clicked and the list of choices pops up, but trying to click the relevant menu item throws this error:

listofitems returns 0 items.

What is going on here? How do I click/select the required item?

BTW, the grayed out code does not work either. It selects the right sub item in the pop up menu, but for some inexplicable reason keystroke return does not do anything!

Hi.

Just downloaded 11.0. The button’s not a pop-up:

tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		tell window 1
			click (first button whose name is not missing value and name is not "iTunes Store")
			-- The click produces a new window 1 whose scroll area 1 contains an outline 1. Obviously the 'window 1' reference now refers to this new window.
			tell outline 1 of scroll area 1
				repeat until it exists
					delay 0.2
				end repeat
				click UI element 1 of (first row whose value of static text 1 of UI element 1 contains "TV")
			end tell
		end tell
	end tell
end tell

“TV shows” is “TV Programmes” on my machine, probably an adaptation to my en_GB language preference.

Hi,
I’m new here and have no idea of how to post a new thread.
Can someone help me with this one?
Thanks

Hi ludwip. Welcome to MacScripter.

Assuming you have a query involving AppleScript, go to http://macscripter.net/viewforum.php?id=2 and click the “Post new topic” link to the right above the thread list. Posting guidelines are here: http://macscripter.net/guidelines.php.

Nigel

I get the following error message with your script:

I am not following the syntax, I have to confess. Any suggestions?

Cheers

Nigel

UI Browser identifies the button as a pop up button:

What am I missing?

My best guess is that you’re using a different OS version from mine and the GUI set-up’s different for the two systems.

On my Snow Leopard system, what looks like a pop-up button is in fact just a ‘button’ to System Events. Clicking it produces not a ‘menu’ but a menu-like sheet which is classed as a ‘window’. This new window contains only a ‘scroll area’, which contains an ‘outline’, which contains five ‘rows’. The first row’s a header and the other four are what would be menu items if the window was a ‘menu’. However, it’s appears to be necessary to click the first (and only) ‘UI element’ of the desired row, not the row itself.

I suppose that even if the button’s is a ‘pop up button’ on your system, the ‘menu’ could still be another ‘window’ as on mine. :confused:

Nigel

I have tried this:

tell application "System Events"
	tell application process "iTunes"
		tell window 1
			click pop up button 1 --(first button whose name is not missing value and name is not "iTunes Store")
			-- The click produces a new window 1 whose scroll area 1 contains an outline 1. Obviously the 'window 1' reference now refers to this new window.
			tell UI element 1
				tell scroll area 1
					tell outline 1
						--repeat until it exists
						delay 0.5
						--end repeat
						click UI element 1 of (first row whose value of static text 1 of UI element 1 contains "TV")
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

… based on this https://dl.dropbox.com/u/117177/UIBrowser%20Info.png

But get this:

Looks like your script was on the right track, but for some reason cannot get it to work on 10.8 here.

Thanks for your help,

I’ve managed to post it.

Regards

I suppose you could fall back on something like this: :wink:

tell application "iTunes"
	activate
	--reveal playlist "TV Programmes"
	reveal (first playlist whose name contains "TV")
end tell

Edit: Better still:

tell application "iTunes"
	activate
	reveal (first playlist whose special kind is TV Shows)
end tell

Hello

This one does the trick here with 10.8.2, iTunes 11 in french.


tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		tell window 1
			try
				click (first button whose name is not missing value and name is not "iTunes Store")
			end try
		end tell # window 1

		# Now, speak to the new window 1

		tell window 1 to tell outline 1 of scroll area 1 of splitter group 1
			repeat until it exists
				delay 0.2
			end repeat
			(* In French, the target row is « Séries TV » *)
			(first row whose value of (static text 1) contains "TV")
			set value of attribute "AXSelected" of result to true
		end tell # window 1
	end tell # process
end tell # System Events

Yvan KOENIG (VALLAURIS, France) dimanche 2 décembre 2012 14:19:13

Aha! The GUI Scripting approach also depends on whether or not the “sidebar” (Option-Command-s) is showing. Yvan’s script works if it is. My GUI script works (or not) if it isn’t.

But the direct (iTunes dictionary) alternatives a couple of posts up are preferable either way.

Thanks for all these posts.

Nigel’s direct route is the best.

But I have one further question. I have a HomeShare iTunes library which appears in the drop down list. But the direct route above does not work to reveal the home share library.

I suspect this is because home share is not a playlist.

What would be the correct terminology to reveal the homeshare library?

I have tried to reveal “user playlist” and “library playlist” but these have not worked…

Cheers

I have also tried Yvan GUI scripting and cannot get this to work on 10.8.2, iTunes 11 English version.

I just get error :

Sigh…

OK. I got Yvan’s script working. As was pointed out, needs side bar activated…

And works for connecting to home share libraries.

But if there is a direct way to reference home share libraries using iTunes dictionary, I would be keen to know/learn.

Basically, I want my iTunes on Macbook to auto connect to main iTunes library on server whenever it is launched.

Cheers

Just for the fun, this version is supposed to work in both cases.


tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		set needShortcut to false
		try
			position of first pop up button of window 1
			# Here if the sidebar is unavailable
			set needShortcut to true
			# Show the sidebar
			keystroke "s" using {option down, command down}
			delay 0.1
		end try
		
		# Now, speak to the new window 1
		
		tell window 1 to tell outline 1 of scroll area 1 of splitter group 1
			repeat until it exists
				delay 0.2
			end repeat
			(* In French, the target row is « Séries TV » *)
			(first row whose value of (static text 1) contains "TV")
			set value of attribute "AXSelected" of result to true
		end tell # window 1
		# Hide the sidebar if we revealed it
		if needShortcut then keystroke "s" using {option down, command down}
	end tell # process
end tell # System Events

Bien le bonjour de Vallauris :wink:

Yvan KOENIG (VALLAURIS, France) dimanche 2 décembre 2012 19:09:56

Hi Yvan

I had cobbled together the following script, built around your script, which works:

tell application "iTunes" to activate
tell application "System Events"
	tell application process "iTunes"
		try
			click menu item "Show Sidebar" of menu 1 of menu bar item "View" of menu bar 1
			delay 1
		end try
		tell window 1
			try
				click (first button whose name is not missing value and name is not "iTunes Store")
			end try
		end tell # window 1
		
		# Now, speak to the new window 1
		
		tell window 1 to tell outline 1 of scroll area 1 of splitter group 1
			repeat until it exists
				delay 0.2
			end repeat
			repeat with n from 1 to 10
				try
					(first row whose value of (static text 1) contains "Server")
					set value of attribute "AXSelected" of result to true
					delay 1
					exit repeat
				end try
				delay 1
			end repeat
		end tell # window 1
		try
			click menu item "Hide Sidebar" of menu 1 of menu bar item "View" of menu bar 1
		end try
		--delay 10
	end tell # process
end tell # System Events

I have it autorun, using DSW, when iTunes launches and all seems to work well, irrespective of how iTunes is set up.

Of course, if there is an iTunes dictionary solution, that would be much better. But in the meantime, we have a solution.

Bien à vous et merci depuis le Limousin…

Hi,

I recommend to control showing and hiding the sidebar rather than using try blocks


activate application "iTunes"
tell application "System Events"
	tell application process "iTunes"
		set sidebarIsVisible to exists splitter group 1 of window 1
		if not sidebarIsVisible then
			keystroke "s" using {command down, option down} -- show sidebar
			repeat until exists splitter group 1 of window 1
				delay 0.2
			end repeat
		end if
		
		-- .
		
		if not sidebarIsVisible then
			keystroke "s" using {command down, option down} -- hide sidebar
		end if
	end tell # process
end tell # System Events

Thanks, Stefan

No top tips for direct action under iTunes dictionary to connect to home share library:)

A

I don’t use home sharing.

If the library is not treated as a playlist, there’s no way to access it via iTunes dictionary