Scripting New iTunes 11 - item of pop up button

OK. Glad to clear that up:)

Thanks

On my Snow Leopard System (the one where my GUI script works), the main window of iTunes 11.0 has a splitter group 1 whether the sidebar’s showing or not. It would probably be better to test to test if ‘(splitter group 1 of splitter group 1 of window 1 exists)’ or if ‘(name of static text of rows of outline 1 of scroll area 1 of splitter group 1 of window 1 contains {{“Home Sharing”}})’.

Thanks, I tested it only on Lion

Hello Nigel

I’m not sure that testing the availability of the string “Home Sharing” is a good idea.
As you will see below, it’s a localizable string.
EDIT : As I don’t use this feature, Home Sharing/Partage à domicile, is not displayed on my copy.
One more reason to don’t use it as a state flag

In fact I was back here to post a short piece of code able to grab some localized strings :


set beg to "163.0"
set local_items to {}
repeat with i from 86 to 91
	tell application "iTunes" to localized string (beg & i)
	set end of local_items to beg & i & " : " & result
end repeat
local_items
--> {"163.086 : Musique", "163.087 : Films", "163.088 : Séries TV", "163.089 : Podcasts", "163.090 : Livres", "163.091 : Apps"}

tell application "iTunes" to set TV_local to localized string (beg & 88)
--> "Séries TV"

tell application "iTunes" to set HomeSharing_local to localized string "9000.040"
--> "Partage à domicile"
tell application "iTunes" to set HomeSharing_local to localized string "kMenuItemSharing"
--> "Partage à domicile"

Maybe a test upon the pop up button would be OK for the different systems.
It behave flawlessly with Mountain Lion.


tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		set needShortcut to false
		if (exists pop up button 1 of window 1) then
			# Here if the sidebar is unavailable
			set needShortcut to true
			# Show the sidebar
			keystroke "s" using {option down, command down}
			delay 0.1
		end if
		
		# 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

Other scheme : test the status of the menu item ruling the sidebar :


tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		set {mt, mi} to {5, 5} # Présentation > Masquer ou Afficher la barre latérale
		tell menu bar 1 to tell menu bar item mt to tell menu 1
			set needShortcut to get enabled of menu item mi
			if needShortcut then click menu item mi
		end tell -- menu bar.
		
		# 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

Alas I don’t know, if the menu is the same under the different OS.

Yvan KOENIG (VALLAURIS, France) dimanche 2 décembre 2012 22:41:48

Hi Yvan. Yes. Sorry. I was aware of that when I posted. But I was watching something on television and reckoned you’d know more about localised strings than I do. :wink:

I don’t use it either ” in fact, I rarely use iTunes at all ” but “Home Sharing” is displayed in my copy.

Except that, as I mentioned somewhere above, it’s not a pop up button on my machine but an ordinary button which looks similar to a pop up.

That should be the best method, but the only difference in the menu item here is the verb in the name. :frowning:

But that’s the nature of GUI Scripting. At least it sounds as if kiwilegal’s got something that will serve the turn until the next iTunes or system update. :slight_smile:

Hello

Happily, it’s easy to grab the localized string used to display the menu items.

“kMenuItemShowSourcesList” = “Afficher la barre latérale###S#option”;
“kMenuItemHideSourcesList” = “Masquer la barre latérale###S#option”;

So, to check if we must issue the shortcut we just need to check if the local value of the string “kMenuItemShowSourcesList” contains the name of the 5th menu item.


tell application "iTunes" to set showSidebar_local to localized string "kMenuItemShowSourcesList"
--> "Afficher la barre latérale###S#option"
(*
tell application "iTunes" to set hideSidebar_local to localized string "kMenuItemHideSourcesList"
--> "Masquer la barre latérale###S#option"
*)
tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		set {mt, mi} to {5, 5} # Présentation > Masquer ou Afficher la barre latérale
		tell menu bar 1 to tell menu bar item mt to tell menu 1
			name of menu item mi
			--> "Afficher la barre latérale" ou "Masquer la barre latérale"
			set needShortcut to showSidebar_local contains result
		end tell -- menu bar.
		if needShortcut then keystroke "s" using {option down, command down}
		# 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

Just for info,
in Japanese:
“kMenuItemShowSourcesList” = “サイドバーを表示###S#option”;
“kMenuItemHideSourcesList” = “ã‚µã‚¤ãƒ‰ãƒãƒ¼ã‚’éš ã™###S#option”;
in Russian:
“kMenuItemShowSourcesList” = “Показать боковое меню###S#option”;
“kMenuItemHideSourcesList” = “Скрыть боковое меню###S#option”;

Yvan KOENIG (VALLAURIS, France) lundi 3 décembre 2012 10:58:30

. or the 4th in Snow Leopard. :wink:

Edit: Here’s another idea:

tell application "System Events"
	tell application process "iTunes"
		set frontmost to true
		set sidebarMenuItem to first menu item of menu 1 of menu bar item 5 of menu bar 1 whose (value of attribute "AXMenuItemCmdChar" is "S") and (value of attribute "AXMenuItemCmdModifiers" is 2)
	end tell
end tell

Thanks Nigel

Which are the menu items in Snow ?
Did they reverted sidebar and statusbar or was the statusbar item unavailable ?

This edited version seems to be safe (assuming that the user didn’t change it’s shortcut ;))



tell application "iTunes" to set showSidebar_local to localized string "kMenuItemShowSourcesList"
--> "Afficher la barre latérale###S#option"
(*
tell application "iTunes" to set hideSidebar_local to localized string "kMenuItemHideSourcesList"
--> "Masquer la barre latérale###S#option"
*)
tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		name of first menu item of menu 1 of menu bar item 5 of menu bar 1 whose (value of attribute "AXMenuItemCmdChar" is "S") and (value of attribute "AXMenuItemCmdModifiers" is 2)
		--> "Afficher la barre latérale" ou "Masquer la barre latérale"
		set needShortcut to showSidebar_local contains result
		
		if needShortcut then keystroke "s" using {option down, command down}
		# 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

Yvan KOENIG (VALLAURIS, France) lundi 3 décembre 2012 17:16:05

Hi Yvan.

I can’t find any mention of a “statusbar” or status bar.

Hello

Statusbar is available under 10.8.2 and maybe under 10.7.x.

Yvan KOENIG (VALLAURIS, France) mardi 4 décembre 2012 11:12:19

Hi Yvan.

As I’ve just e-mailed you, the iTunes 11.0’s status bar exists in Snow Leopard, but isn’t hideable. The screenshot you sent me shows the hide/show keystroke on your system to be ⌘/.

Oops, I failed to edit the shortcut after a copy/paste of the sidebar row to add the statusbar one :frowning:

Yvan KOENIG (VALLAURIS, France) mardi 4 décembre 2012 15:56:49

Exactly what I was looking for. I like Nigel’s reveal playlist method best; it’s simple. Thought it seems none of the methods except using the sidebar work for selecting Apps.

Here is a piece of code extracting the list of every applications




tell application "iTunes" to set showSidebar_local to localized string "kMenuItemShowSourcesList"
--> "Afficher la barre latérale###S#option"
tell application "iTunes" to set apps_local to localized string "163.091"
--> "Apps"
(*
tell application "iTunes" to set hideSidebar_local to localized string "kMenuItemHideSourcesList"
--> "Masquer la barre latérale###S#option"
*)
tell application "iTunes" to activate

tell application "System Events"
	tell application process "iTunes"
		name of first menu item of menu 1 of menu bar item 5 of menu bar 1 whose (value of attribute "AXMenuItemCmdChar" is "S") and (value of attribute "AXMenuItemCmdModifiers" is 2)
		--> "Afficher la barre latérale" ou "Masquer la barre latérale"
		set needShortcut to showSidebar_local contains result
		
		if needShortcut then keystroke "s" using {option down, command down}
		# 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) is apps_local)
			set value of attribute "AXSelected" of result to true
		end tell # window 1
		tell window 1 to tell first splitter group
			tell first radio group
				name of radio buttons
				--> {"Tous", "iPhone/iPod touch", "iPad", "Jeux iPod", "Liste"}
				click radio button 5 # Activate List mode
			end tell
			
			tell scroll area -1 to tell outline 1
				value of text field of every row # extract the list of every apps installed
			end tell
			
		end tell
	end tell # process
end tell # System Events

Yvan KOENIG (VALLAURIS, France) mercredi 5 décembre 2012 10:29:29

Thanks Yvan. Works well. I just wanted the scripts so I could make macros that could switch views.

Btw, the Apps review doesn’t respond to the reveal command so your way is the way.