Automate the creation of a portable iTunes library

Jan 25, '07 07:30:00AM

Contributed by: Anonymous

My MacBook Pro's 100GB hard drive is not enough for my ever-growing collection of movies and music. So I purchased a 1TB external USB2 drive, which is a great solution when I'm not on the go. But sometimes, being a laptop, I want to have my music with me. It seems somewhat difficult to manage multiple iTunes libraries, and it's something I don't want to touch.

I solved this problem with two Automator scripts, VLC, and a Preference Pane called Do Somthing When. The first step is to get our tools:

  1. Do Something When...
  2. VLC
First, install Do Something When... according to the instructions that come on the disk image. Second, put VLC somewhere in your Applications folder -- or, really, wherever. We'll come back to these in a second.

Now for the Automator magic. Open up Automator and create this sequence of actions:

  1. iTunes -> Get Tracks of Selection or Selected Playlist
  2. Finder -> Copy Finder items
  3. Finder -> Open Finder items:
  4. Automator -> Run Applescript:
Okay, now save this in ~/Library -> Scripts -> Applications -> iTunes as a workflow. Next, Automator script number two (File -> New in Automator):
  1. Automator -> Run AppleScript:
  2. Automator -> Run Shell Script:
Save this as an Application anywhere you like, and also a workflow in ~/Library -> Scripts -> Applications -> VLC. Now, for Do Something When (DSW). Assuming you have DSW installed, open up System Preferences and go to DSW.
  1. In the Rule Name field, type in Docked Songs
  2. When [the external hard drive mounts] . . .
  3. Open [The application you made in Automator in script number two above]
I also created a Smart Playlist in iTunes called Undocked. This step isn't neccessary, but it helps. I set it to match any of the following rules (your mileage may vary): Genre contains Elect, Metal, Soundtrack, Classical, New Age. Limit to 210 minutes selected by least recently played.

So, what exactly is this thing going to do? Well, I'll demonstrate. Once you've placed the actions in their appropriate locations, when iTunes is up, you'll now have a new item in your system script menu. I called mine Undocked. Running it does the following:

It takes either the selected playlist's contents, or the individual files you've selected, and copies them to a folder in the Finder. It then quits iTunes and opens those items up in VLC. Boom. You've now got a temporary playlist. Now, in VLC, you'll have a menu called Docked or whatever you called the actions from the second Workflow. Running this quits VLC, opens iTunes, and deletes the files you temporarily used.

Using Do Something When... automatically sets it up so that whenever the external drive is mounted, it will run through the application version of the Automator script #2 (killing VLC, launching iTunes, deleting temporary songs), which is a nicety.

As for the smart playlist, I set it up so that it lasts approximately the duration of my battery -- why have it any longer if you'll be plugging in the machine (and probably docking it) at some point?

And that's it. It may seem a bit convoluted, at first, but it has been working really well for me. The advantage of this over doing these steps manually in the Finder is the fact that you don't have to hunt for each file individually, drag them over to a folder and then open VLC and drag the files into it. It's really quite handy if you're in a similar situation to mine.

[robg adds: I haven't tested this one, but note that the script contains an rm -r *. If you're going to test this one, please make sure you've got the paths correct, and that you have a recent backup of your files, just in case something goes wrong.]

Comments (2)


Mac OS X Hints
http://hints.macworld.com/article.php?story=200701241723198