Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Automate the creation of a portable iTunes library Laptop Macs
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
    • To: [A folder of your choice. (/path/to/folder)]
    • Check replace existing files.
  3. Finder -> Open Finder items:
    • Open with: VLC
  4. Automator -> Run Applescript:
    • tell application "iTunes"
        quit
      end tell
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:
    • tell application "VLC"
        quit
      end tell
      tell application "iTunes"
        run
      end tell
  2. Automator -> Run Shell Script:
    • cd path/to/folder
      rm -r *
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.]
    •    
  • Currently 2.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[20,699 views]  

Automate the creation of a portable iTunes library | 2 comments | Create New Account
Click here to return to the 'Automate the creation of a portable iTunes library' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automate the creation of a portable iTunes library
Authored by: quasma on Jan 25, '07 10:29:18AM

It would be better to do:

rm -f path/to/folder/*

rather than

cd path/to/folder
rm -r *



[ Reply to This | # ]
Automate the creation of a portable iTunes library
Authored by: taxi on Jan 29, '07 04:06:05AM

Both of these are potentially dangerous.

Consider this:
cd /
cd /Alphabet/Soup/Tastes/Nice
rm -r *

(Naturally, /Alphabet/Soup/Tastes/Nice doesn't exist). I think this is the instance the previous poster suggests. No second 'cd' occurs, resulting in everything on the disk being removed.

Alternately, what about:
cd /
rm -r /Alphabet/Soup/Tastes/Nice/ *

You might notice the space in there. It's fairly easy in coding to have a space remaining on a string that you didn't mean to leave there. Bye-bye contents of / again.

rm -r * is dangerous, although running as a low-privs user makes it somewhat safer. As does backing stuff up.

[ Reply to This | # ]