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

Switch between two iTunes Libraries Apps
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!]
    •    
  • Currently 2.60 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)
 
[124,438 views]  

Switch between two iTunes Libraries | 19 comments | Create New Account
Click here to return to the 'Switch between two iTunes Libraries' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Switch between two iTunes Libraries
Authored by: diablo943 on Nov 28, '05 08:37:23AM

I use a simple system of folders and aliases to accomplish the same thing and am able to have 3 or more iTunes libraries and switch between them easily. First I created three folders named by their location (server, traveling drive, local). I also color coded them with the label colors. Within each folder I created aliases to the iTunes music folder that contains the music and the library, etc. I color coded each of the aliases to match their containing folders. When I want to listen to music contained on the server, I move the alias out of its container folder and into the Music folder. When I want to listen to music on the local drive, I move the alias that is currently in the music drive back into its container folder and move the local alias out of its container and into the Music folder.

I looked into setting up Automator actions to accomplish this, but since I use three different iTunes libraries, I would have to use some logic to handle the options and Automator is unable to do that. No big deal. Manually moving is easy enough!



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: river_jetties on Jun 02, '06 11:05:08AM

Mabye I'm missing something but this doesn't seem to work. In iTunes 6, aliases appear to be resolved to the original link.



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: Taper on Nov 28, '05 08:42:46AM
To get around the need for those dangerous-looking rms, you can change
rm iTunes\ Library
rm iTunes\ Music
ln -s $opposite_lib iTunes\ Library
ln -s $opposite_music iTunes\ Music
to
ln -sf $opposite_lib iTunes\ Library
ln -sf $opposite_music iTunes\ Music
The -f flag forces the creation of the new symbolic link over the old one; unlike the rm, this can only replace a file that's already a symlink.

[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: efge on Nov 28, '05 05:40:31PM

That's not true, ln -sf will happily overwrite a normal file.



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: sweth on Nov 28, '05 08:45:57AM
This seems way over-complicated. Why muck around w/ multiple files within the ~/Music/iTunes dir, vs. just pointing that dir itself somewhere else? To fix the problem w/ rm-ing the Library potentially being dangerous, just wrap those lines in a block that tests if the thing being rm-ed is a link or not:

if [[ -h /thing/to/be/relinked ]] ; then
   rm /thing/to/be/relinked
   ln -s /new/destination/for/link /thing/to/be/relinked
else
   echo "/thing/to/be/relinked isn't a link!" > /dev/stderr
   exit 1
fi


[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: windrag on Nov 28, '05 09:49:49AM
Doug Adams excellent iTunes Library Manager does this with a GUI, and you can name your Libraries. I've used it for a couple of years and swear by it. It will manage 2 Libraries for free or more for $5.

---
Ryk A. Groetchen | 700MHz iBook 16 VRAM G3 | 640MB RAM | OS X 10.4.1

[ Reply to This | # ]

Switch between two iTunes Libraries
Authored by: XplodingBoy on Nov 28, '05 10:18:31AM

The shareware app "Libra" (http://homepage.mac.com/sroy/libra/) does an excellent job of creating and managing multiple iTunes libraries also.



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: tjj on Nov 28, '05 10:38:39AM

Couldn't you just change the Music Folder entry in the iTunes plist file?



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: book on Nov 28, '05 10:25:13PM

The idea here is having two separate libraries, with different music. In my experience, just changing the music folder leaves you with a library that has links to the old songs (which may be on the disconnected drive).



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: mania on Nov 28, '05 02:28:38PM

Well, I for one have tried the Dougs script and the problem was if you forgot to switch the library you were hosed and I actually screwed up my libary bigtiime because of it and had to reimport thus loosing all my star ratings. I am not a newbie either so I would say this seems like a better way if you cron job it to check if the dir exists etc - I will play with it and see what improvements I can ad to the mix.

This is not a simple problem with a simple solution so all of you who are saying can't you just [insert simple idea here] the answer is no.



[ Reply to This | # ]
Mmm, environment variables
Authored by: boredzo on Nov 28, '05 02:38:01PM
instead of /Users/me, just use $HOME. then the script needs no user editing.

[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: Terry Moore on Nov 28, '05 05:15:07PM

Not so hot for ipod syncing... :(



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: Dephex Twin on Nov 28, '05 06:36:09PM

I made an eerily similar program in AppleScript about a year ago. But instead of being run when you want to switch, it is an application that you can put in the dock instead of iTunes. When you launch it, it checks to see if the remote server is mounted, and if so, launches iTunes with that library. If the remote server is not mounted, it asks if you want to try to connect to it, or otherwise launch iTunes with the local library. That way, you don't have to keep track of whether you're toggled for remote or local, or whether you're already/still connected to the remote server or not (which is particularly useful in the case of using a remote library over a network).

(And I guess if you are using a directly connected external hard drive, you could just remove the network mounting part out of my script so it would launch the local right off the bat if the external isn't mounted.)

---
"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: martyl on Nov 28, '05 09:14:54PM

Is there any way for you to post that script? Sounds like it's just what I'm looking for...

Thanks!!

---
Marty Lindower



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: Dephex Twin on Nov 29, '05 05:05:16PM

Here it is, I couldn't do the indenting, but if you copied this into AppleScript it would of course indent it for you:


(*

The only thing extra you need to set up for this is creating two folders in the Music folder of your client computer. (Actually you can put these folders anywhere on the client but in my code it is the Music folder.) The folders are named "iTunes Data Local" and "iTunes Data Server" in my code. Take the two library files ("iTunes 4 Music Library" and "iTunes Music Library.xml") that you currently have in the client iTunes folder and put them in the "iTunes Data Local" folder. Now mount the server and go to the equivalent place on the server where its two library files are. Make aliases to those files and put those aliases on your client where the originals were.

The program will be swapping the original client settings and the aliases to the server ones, and that is basically how it works.

It should be obvious which parts you need to customize but if not then let me know.

*)


try

do shell script "top -l1 | grep -w iTunes"

--Check to see if iTunes is already running on the laptop, in which case do nothing.

on error

tell application "Finder"

set useServer to true

try

set localFolder to folder "iTunes" of folder "Music" of home

end try

try

set serverFolder to folder "iTunes" of folder "Music" of disk "Server HD"

--Try to make a reference to the server hard drive

on error

--Making the reference failed, and that means the laptop is not connected to the server yet.

display dialog "Not connected to music server. Connect?" buttons {"Use Local", "OK"} default button "OK"

if button returned of the result is not equal to "OK" then

set useServer to false

else

try

mount volume "afp://yourlogin@yourserver.local/server_harddrive_name"

--this mounts the server drive, I don't put in the password here for security reasons, but you can put it in like this:

-- afp://yourlogin:password@yourserver.local/server_harddrive_name

on error

display dialog "Could not connect to server."

quit

end try

end if

end try

if useServer then

-- Depending on what is being used, local or server

set folderBeingUsed to (folder "iTunes Data Server" of folder "Music" of home)

set otherFolder to (folder "iTunes Data Local" of folder "Music" of home)

else

set otherFolder to (folder "iTunes Data Server" of folder "Music" of home)

set folderBeingUsed to (folder "iTunes Data Local" of folder "Music" of home)

end if

if (count of items of folderBeingUsed) is less than 1 then

try

--If the folder I am getting settings from is empty, that means the settings are already in the right place, so just run the program

open application "iTunes"

end try

else

--This swaps the settings that are currently there with the other ones.

set theFiles to {file "iTunes 4 Music Library" of folder "iTunes" of folder "Music" of home, file "iTunes Music Library.xml" of folder "iTunes" of folder "Music" of home}

move theFiles to otherFolder

set theFiles to {file "iTunes 4 Music Library" of folderBeingUsed, file "iTunes Music Library.xml" of folderBeingUsed}

move theFiles to folder "iTunes" of folder "Music" of home

try

open application "iTunes"

end try

end if

end tell

end try

end if

---
"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"

[ Reply to This | # ]

Switch between two iTunes Libraries
Authored by: Dephex Twin on Nov 29, '05 05:08:47PM

Oh, and if you wanted this to just work for an external drive instead of on a network, you could just cut out everything after "on error" up to before the second "end try", and insert the line "set useServer to false"

---
"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"



[ Reply to This | # ]
Two bugs in your script...
Authored by: phow4rd on Dec 02, '05 04:46:48PM

#1: There's an extra "end if" at the end.

#2: Every instance of "iTunes 4 Music Library" should be changed to "iTunes Library" (assuming you're not using iTunes 4.x).

I haven't finished testing it yet, and I want to integrate the choice of using an external drive, so I'll post more later.



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: parkavedavinci on Nov 29, '05 06:34:22AM

I would be really interested as well.



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: computerboy0 on Jun 28, '08 08:02:17AM

This is quite easy without going to the trouble of creating odd scripts.
Mac users: Hold down the Option key while you open iTunes.
Windows users: Hold down the Shift key while you open iTunes.
Click Choose Library, then go to where youve got your second third etc. library, then click on the .itl file, and click ok.

Do the same to get back to your old or another library.
You can have unlimited libraries this way.
(unlimited by itunes. Disk space however....)



[ Reply to This | # ]