Toggle iTunes 11 MiniPlayer
November 29th, 2012Today, Apple released iTunes 11, the anticipated update that has been due “sometime in November” since they announced it earlier this year. Judging from reactions on Twitter it’s having a mixed response: the new UI is, as expected, either refreshing or distressing depending on your particular attachment to the old look-and-feel, and the extent to which the new look speaks to you.
Folks who use FastScripts or another utility to script iTunes will be pleased to know that much of its scriptability is unchanged. I’m able to use my variety of scripts for playing and pausing, showing track information, etc., without any issue. But some subtle things have changed, including support for minimizing or maximizing the iTunes window. My friend Gabriel Roth framed the problem on Twitter:
@danielpunkass Seems iT11 breaks the AppleScript “minimized” property—it now means “shrunk in the Dock” rather than “in mini player state.”
— Gabriel Roth (@gabrielroth) November 29, 2012
I scratched my head about a proper workaround for this. Indeed, not only does the minimized property behave differently than documented in the scripting dictionary, the new “MiniPlayer” is an independent window from the main window. Although they seem to toggle between one another, you can actually select and make both visible from the “Window” menu in iTunes.
My first thought was to simply hide one window while making the other visible. This would be a fine solution except another bug in iTunes 11 apparently prevents the new MiniPlayer window from being exposed to the scripting object hierarchy.
So the compromise is to resort to UI scripting. By simulating the selection of iTunes’s own “Switch” menu item, we can rest assured that the toggle will happen as naturally as possible given the constraints we are facing.
Download the Toggle iTunes MiniPlayer script if you interested in hooking up a hotkey or otherwise automating display of the iTunes 11 MiniPlayer.
Update: Doug Adams (of Dougscripts.com fame) pointed out in the comments that my original solution was less ideal because scripters on non-English systems would need to open and modify the script to search for the correctly named item. I was able to update the script to search instead for the item by its keyboard shortcut alone. This should make the script more immediately useful to users of iTunes 11 regardless of the primary language they run their Mac with.
November 29th, 2012 at 3:05 pm
UI scripting seems like a roundabout way of setting a hotkey….
November 29th, 2012 at 4:51 pm
Eurobubba: it’s not “just a hotkey.” This is a general purpose script for achieving the toggling. Some people will use it to tie to a hotkey, others will find other creative uses for it. The main point here is iTunes lost scripting functionality and this replaces it with a workaround.
To the point you’re getting at (clarified by your tweet), the specific example here of using e.g. FastScripts to assign a hotkey is more than just changing the hotkey for the menu item in iTunes. The hotkey via FastScripts would be accessible globally on the system regardless of whether iTunes is front-most. That’s often the use case for this kind of scrip to be able to toggle something about iTunes regardless of whether it’s focused or not.
November 29th, 2012 at 5:03 pm
Someday someone will develop a monster utility that grafts the menubars from every active application into one unholy, system-wide, hotkey-activated pop-up menu. And I will be the first to buy it. (Not from the App Store, presumably.)
November 30th, 2012 at 6:40 am
Pity can’t use numbered menu item so non-English users don’t have to translate.
November 30th, 2012 at 8:39 am
tell application “System Events”
tell application “iTunes” to activate
keystroke “m” using {command down, option down}
end tell
November 30th, 2012 at 9:34 am
Doug: I considered that first but the problem there is you have to accept activating iTunes as part of the script execution. Another worry I have about that method is I have observed problems with UI scripting where, unless a delay is imposed after activation, the keyboard shortcut may not yet be “wired up” to the system by the time the keystroke event fires.
November 30th, 2012 at 9:40 am
Doug: there seem to be a variety of “mystery” accessibility attributes, besides the obvious ones like “title” etc. I see from Accessibility Inspector that the menu item exposes a kAXMenuItemCmdCharAttribute of “M” so it might be possible to interrogate the items for this attribute and choose the menu item to “click” based on that.
November 30th, 2012 at 9:54 am
Doug: OK – it got me thinking and I was able to modify the script to be completely language-independent. It only requires that the target item expose Cmd-Opt-M as the shortcut. In my brief tests I confirmed this worked in several languages so I am guessing iTunes never localizes the shortcut.
Download the script again to check out the changes.
December 2nd, 2012 at 10:02 am
Hmmm… a giant step backward if you ask me. If it ain’t broke, why fix it? Now my mini-player window no longer updates the titles of the music stream I listen to.