Does anyone else find it annoying how difficult it is in iTunes to switch between Shuffle by Song and Shuffle by Album? It requires a trip to the Preferences window. Couldn’t Apple have made the Shuffle button a 3-way toggle, like the Repeat button? Ah well.
So I had the brilliant idea of creating an AppleScript to do the job. Not so easy, as it turns out. First of all, Preferences aren’t scriptable in iTunes (as of version 4.5). Second of all, even using Apple’s new GUI Scripting (System Events), I can’t seem to get this to work.
The first problem is that the iTunes Preferences window is divided into 7 screens, and the option I want to get at is in the Advanced screen. But the window doesn’t use standard tabs to switch between screens. Using the UIElementInspector, I see that the row of icons across the top of the window is one UI element. I suppose I could do a “click at”, but I haven’t been able to get that to work.
But assuming I could, or assuming that the Preferences window always defaults to the Advanced screen, I still can’t get the radio button in quetion (“Album”) to be selected. Here’s my script so far:
tell application "iTunes" to activate
tell application "System Events"
tell process "iTunes"
click menu item "Preferences…" of menu "iTunes" of menu bar 1
delay 1
tell window "Advanced"
click radio button "Album"
end tell
end tell
end tell
Everything works up to the “click radio button” command. At that point, I can actually witness the radio button flash a bit (as if you clicked but didn’t release the mouse in the radio button), but it does not get selected.
Any help is greatly appreciated.
-Frederik