Recently I decided it was finally time to pick up a pair of ‘proper’ speakers.
While a few years ago I ripped all my music to FLAC and played it through Foobar2000, when I picked up my MacBook in 2010 I realised there were a couple of obstacles to keeping this up:
1.) iTunes doesn’t play FLAC. I’d need to re-encode to ALAC or switch player. 2.) I no longer had the storage space to keep lossless copies of my music.
So I re-encoded everything to tiny V0 MP3 files and packed up my FLAC’s onto an external drive to put in the bottom of my cupboard.
Facing this problem now, however, with a newfound need for better quality files, there’s a better solution available: iTunes Match. When I’m mobile I don’t need high quality audio files. Streaming my library when I’m out of the house and playing lossless files from an external drive when I’m at home seems like the perfect solution.
The only problem is that iTunes actually doesn’t like losing track of your files. Even if you’ve subscribed to Match and uploaded (or matched) your library, pointing iTunes in the direction of a missing local file doesn’t result in streaming but instead a giant exclamation mark.
If you want to manage two libraries, one in the cloud and one stored locally, you do literally need to create two iTunes libraries. Hold down option when starting iTunes and hit ‘Create new Library’, point it to where you want to store it and off you go.
So if you want the setup described above, you need to match your local library, make a new one and then switch to that one. Your music should stream from one library and play locally from the other.
Not exactly intuitive.
Enter Applescript (not dead yet)
Of course some kind soul on Stack Overflow came up with some Applescript to make the process of switching libraries a little easier:
property otherLibraryLocation : "" -- paste location between the quotes property libraryLocationPref : "com.apple.iTunes 'alis:1:iTunes Library Location'" -- first, quit iTunes if it's running tell application "System Events" if exists (application process "iTunes") then tell application "iTunes" to quit end if end tell -- then, set the location do shell script "defaults write " & libraryLocationPref & " " & quoted form of otherLibraryLocation -- uncomment the following line to use the default iTunes library instead -- do shell script "defaults delete " & libraryLocationPref -- finally, relaunch iTunes tell application "iTunes" to activate
Pick a library, put this in the Terminal:
defaults read com.apple.itunes 'alis:1:iTunes Library Location' | pbcopy
Then paste the results between the speech marks in the script above. Run it and iTunes will switch to the library you copied the alias for. Do it for both and you’ll have two scripts, one for each library.
You could use an application launcher like Alfred to make running the scripts even easier:
But, of course, we can do better!
ControlPlane is designed to perform actions and tasks based on a set of conditions, such as geographical location or what is (and isn’t) plugged into your computer. This makes it perfect for automatically switching between two two libraries, since one will be stored on an external drive.
I created a new context:
Then created a rule based on the presence of my external drive:
And created two sets of actions, one for when it’s plugged in and one for when it’s pulled out:
Each one run the appropriate Applescript. Plug in the external drive and it runs one to switch to the external library. Unplug and it runs one to switch to the iTunes Match/iCloud library.
Is it a good idea to install an application just to do this? Probably not – but now I have two libraries which automatically switch without me having to think about it – and an appropriate quality of music for my location.
Onwards and upwards.