I have been a Spotify customer for over a year now. But my loyalty for a product ends as soon as i get something better for less. Some days ago, Google opened its Google Music All Access music subscription service to german customers, and that is why it suddenly became interesting for me. If you become a customer before middle of January, you get it for 7,99€ per month, which is 2€ cheaper than Spotify. Apart from the lower price, the Android client app for this service is simply better than Spotify’s app.
I am very happy with this service, but it doesn’t come with an app for the desktop computer. In general, this is not a problem. I am perfectly fine with streaming music via an HTML5 page. The only disadvantage is that i cannot use my Apple keyboard’s media keys any longer. Fortunately, workflows in OS X are scriptable to quite an extent with factory included software. In the end, there is a scripted solution which feels quite native.
Programmatic Access to Media Functions
At first we need some kind of script which can be started to execute some workflow like play/pause the music or go back/forward in the playlist. A function which i consider extremely important is voting up/down the track which is currently played, as i am mostly listening to automatically generated playlists based on my music rating history.
I do not have much exercise in using Apple Script, although this is the obvious way to do it. Apple Script is the extremely versatile and mighty approach to automate stuff in OS X. On this site i found the generic approach to trigger user input events in Google Play:
// Play Previous Song (document.getElementsByClassName('flat-button')).click(); // Play Next song (document.getElementsByClassName('flat-button')).click(); // Rate Current Song Up (document.getElementsByClassName('rating-container thumbs').childNodes).click() // Rate Current Song Down (document.getElementsByClassName('rating-container thumbs').childNodes).click()
These code lines can just be used to substitute line 14 in the Apple Script code listing.
To save such Apple Scripts in a way that they become useful as hotkey-mappable workflow-actions which are globally reachable, we have to save them as a Service using Automator.app. Just start Automator, make a new Service and add a “Run Applescript” action to it. Paste the Applescript into it and set the “service receives” drop down list to “no input”. That is it. Save it with some descriptive name. Services are saved in ~/Library/Services/ by default.
Mapping the Apple Multimedia Keys
Now that we have these input events encapsuled into global services, we can trigger them using keyboard shortcuts. Configure them using System Preferences.app, under Keyboard > Shortcuts > Services.
Assuming that we want to use the original Play/Pause, forward, and back buttons on the Apple keyboard, there is some more remapping necessary as OS X will not let us reconfigure these special buttons. We could remap them if we switch their standard behaviour. Either they represent the F1-F12 keys if we hold the fn button or they represent (not reconfigurable) special functions by default. This is what OS X lets us configure. Of course this is not what we want, because there are just those 3 buttons we want to change – the brightness- and window-management functions shall be left untouched.
KeyRemap4MacBook is the perfect helper in this situation: It lets us switch the standard behaviour for a subset of function keys. We just need to download, install and configure it and wire the Google Play services to the F7-F9 keys. That’s it!
I experienced that the hotkeys do not work immediately. The setting seems to need some time to seep through to all apps. But then it feels perfectly native. Enjoy.