Posted on October 8th, 2009 by Neil Crosby. Filed under Blog Posts.
Over the last few days on Twitter I’ve been talking about my peculiar iTunes setup, and a few people have been asking me if I’ll blog about it. So, here goes…
My situation is that my iTunes music library is stored on my MacMini that lives in my living room (connected to and powering my TV experience). However, most of the time I spend using my MacBook Pro, which spends most of its time in the office upstairs a fair way away from the MacMini. Because I spend most of my time at the laptop, it’s nice to have music available for me to listen to on it. Of course, if I just wanted to listen to music then this would be a very short blog post – I could use iTunes to share the library from the MacMini and listen to the music upstairs, or I could use Spotify or Last.fm. The problem with these as solutions are that I make heavy use of Smart and Genius Playlists in iTunes to generate playlists of music to listen to. Using iTunes’ sharing feature doesn’t allow me to rate tracks in the originating library (even with iTunes 9’s “Home Sharing” feature), and it also doesn’t generate extra playcount in the originating library for the things I listen to. This means my Smart Playlists don’t update in the expected way, and I become a sad panda. Likewise, Genius Playlists don’t work in a usable way when using a shared library, so this doesn’t really work for me.
What I wanted was a way to play my music using the MacMini downstairs, but have the music erupt from the speakers connected to my MacBook Pro. As it turns out, there’s an app for that – Airfoil. This lovely application hijacks audio from one device and sends it out across the network to multiple other devices of your choice, all in sync. So, immediately I was able to use OSX’s Screen Sharing app to connect to my MacMini, start some music playing in iTunes and then have Airfoil pipe it out to my MacBook Pro. It was a solution that was sheer elegance in its simplicity. Yes, you have to wait a second or so after pressing play before you hear anything come out of your speakers, but that’s down to Airfoil making sure all your devices are in sync before it starts to do anything. All in all, it’s brilliant. It costs $25, but that’s a small price to pay for this functionality for me.
The only problem is that in playing music on a different computer than the one you’re on, you’re playing music on a different computer than the one you’re on. So various things, like media keys on your keyboard don’t work in the way you expect. So, whenever I was wanting to do simple things like pause my music I was having to go into Apple’s Screen Sharing app, log into the MacMini and then press the pause button in iTunes. Not ideal. So, I wrote a quick AppleScript in Apple’s Script Editor:
tell application "iTunes" of machine "eppc://macmini-2.local" to playpause
Yup, that’s a really simple AppleScript. Something I wasn’t aware of until a couple of days ago is that it’s possible to run AppleScript that runs AppleScript on a different machine. All you have to do is go into
System Preferences, open the
Sharing panel, and enable
Remote Apple Events. The first time you try to run an event on the remote machine you’ll be asked to enter your credentials on the local machine, which you can save to your keychain for auto-use in the future. Now, if I run that AppleScript then iTunes on the remote machine will toggle its play state, and consequently on my local machine. Awesome.
It’s just as easy to write other scripts as well. For example, to advance to the next track, just change
play (next track).
But we’re still not controlling iTunes on the remote machine with just a keypress. If you’ve got something like Quicksilver installed on your machine then you should be able to simply hook the script up to a key combination of your choice. I don’t currently have Quicksilver installed on this machine (and wasn’t about to install it just for this), so I had to find another alternative. What I’m currently using is FastScripts Lite, a free app that adds an icon to your menubar that contains menu items for any AppleScripts you put in a certain directory. The nice thing about FastScripts is that it also allows you to enter a keypress combo for any of these scripts by going into its
Preferences pane and double clicking on the Shortcut field next to the relevant script. I’ve got
playpause bound to
next track to
previous track to (you guessed it)
ctrl-left. Now I can easily change what I’m listening to with a quick keypress, and I’m happy.
Well, I’m almost happy. I still need to have Screen Sharing open so that I can see what’s actually in the playlist that I’m listening to. There’s a solution to that as well though. All I needed do was create a script that calls some AppleScript on the MacMini, grabs the current playlist info and then outputs it into a web page. I could then use this page as the basis of a Dashboard widget and I’d only ever have to press F12 to see my current playlist. And that’s what I did. To find out how I did it though, you’ll have to read the next post!
If you enjoyed this post, subscribe to The Code Train and read more when I write more.