Switch between two iTunes Libraries

Nov 28, '05 06:43:00AM

Contributed by: xmccorm

If you want to have two iTunes libraries (for example, a large library on an external drive and a small library on a local drive), the following will let you switch between them before starting up iTunes. In my case, I keep the bulk of my music on my external drive, and a small selection of the music I listen to most frequently on my laptop's hard drive, so I can carry it around with me.

Read on for my step-by-step solution...

In Terminal, go to the local iTunes folder, and move aside the original iTunes Library and iTunes Music folders:

$ cd Music/iTunes/
$ mv iTunes\ Library iTunes_Library_lcl
$ mv iTunes\ Music iTunes_Music_lcl
$ ln –s iTunes_Library_lcl iTunes\ Library
$ ln –s iTunes_Music_lcl iTunes\ Music
Then create links to the external library. E.g.:

ln –s /Volumes/path/to/iTunes/iTunes\ Library iTunes_Library_ext
ln –s /Volumes/path/to/iTunes/iTunes\ Music iTunes_Music_ext
Finally, using a text editor (like vi), enter the following script, and give it a name (e.g. switch_iTunes_link.sh):

#!/bin/bash

cd /Users/me/Music/iTunes
current_lib="`ls -l iTunes\ Library | awk {'print $12'}`"
current_music="`ls -l iTunes\ Music | awk {'print $12'}`"
if [ $current_lib == "iTunes_Library_ext" ]; then
  opposite_lib="iTunes_Library_lcl"
  opposite_music="iTunes_Music_lcl"
else
  opposite_lib="iTunes_Library_ext"
  opposite_music="iTunes_Music_ext"
fi
printf "iTunes currently links to $current_lib, $current_musicn";
printf "Switching to $opposite_lib, $opposite_music\n"; 
rm iTunes\ Library
rm iTunes\ Music
ln -s $opposite_lib iTunes\ Library
ln -s $opposite_music iTunes\ Music
After saving the script, make it executable with chmod +x switch_iTunes_link.sh.

Having done all this, simply run the script any time you want to toggle between the two iTunes Libraries, by entering the script name on the command-line:
$ switch_iTunes_link.sh
[robg adds: I haven not tested this one -- and since it's potentially destructive (it uses rm on some files), I'd advise having a current backup before you test it, in case I messed something up in the editing step!]

Comments (19)


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