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.
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
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”}})’.
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 :
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.
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.
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.
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 "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
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 ⌘/.
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.