Multiple iTunes libraries, one music folder
What follows is a solution to a problem that has annoyed a lot of people for some time now.
Suppose you are in a household with two Macs. Each person has a copy of iTunes installed. They both want access to the same music directory, but they both want it to be part of their own library.
iTunes already makes it easy to share your music over a LAN, which is nice up to a point, but doesn’t give you much flexibility: you can’t assign star ratings to someone else’s music, make playlists, or load up an iPod with it. What you really want is for all that music to be yours (and all your music to be similarly available to your cohabitant).
Here’s the recipe. I’ll assume you have a LAN set up already.
- On each computer, go into System Preferences : Sharing : Services and enable “Remote Apple Events”
- Designate one computer as the “music host”; the other will be the “music client.”
- On the client, connect to the host, and mount the hard drive on the host that contains the iTunes music folder. Go into iTunes Preferences : Advanced on the client and set it to use the same folder as the iTunes music folder as the host (the one on the host’s computer)
- In the interest of good file management, you probably want to go into iTunes Preferences : Advanced on the host and enable “Keep iTunes Music folder organized” and “Copy files to iTunes Music folder when adding to library”. However, on the client machine, I think you will need to disable these (otherwise multiple computers will contend over where and how the files should be organized). If the client already has music files stored locally, relocate those files to the host and remove them from the client. Add those tracks to the library of the host computer manually.
- Find and remove the files “iTunes Music Library” and “iTunes Music Library.xml” (or create an archive of them) from the folder ~/Music/iTunes on the client machine. Manually add all the tracks on the host machine to the client’s copy of iTunes by dragging the into the iTunes window. For very large collections, you should probably do this in chunks (iTunes seems to get confused otherwise). I added all the artists starting with A at once, then B, etc. Took a while, but it worked.
- Now both users have access to the same music directory, can make their own playlists, set their own ratings, load up their own iPod, etc. The problem is that the situation is static–if anyone adds a new track, things get out of sync, and only that user will have access to that track (without additional futzing).
- That is where the following mystical-magical script comes in. This was pretty much written by “deeg” (with some nudging from me) in the Applescript for iTunes forum at iPod Lounge.
(*=== Properties and Globals===*) property theDateofLastSync : "" -- date of last sync property theOtherMachine : "" -- ip address of other machine (*=== Main Run ===*) if theDateofLastSync is "" then set theDateofLastSync to ((current date) - 1 * days) -- force date of last sync to sometime ago for first run if theOtherMachine is "" then display dialog "Please enter address of other Mac" default answer "eppc://" set theOtherMachine to text returned of the result end if -- chat with other machine set GotsomeTracks to true try with timeout of 30000 seconds tell application "itunes" of machine theOtherMachine using terms from application "iTunes" activate set theListofTracks to location of file tracks of library playlist 1 where date added > theDateofLastSync end using terms from end tell end timeout on error set GotsomeTracks to false end try -- back to this Machine set SyncedOK to false if GotsomeTracks then set SyncedOK to true try tell application "iTunes" if (count of items of theListofTracks) is greater than 0 then repeat with alocation in theListofTracks add alocation to library playlist 1 end repeat end if end tell on error set SyncedOK to false end try end if -- save sync date if all ok if SyncedOK then set theDateofLastSync to current date
- Copy this script and save it as “sync libraries” to the directory ~/Library/iTunes/Scripts (if you don’t already have a Scripts folder there, create it). Relaunch iTunes and it will be available under the Scripts menu. You can now run this script manually on each computer to update its library against the host. Better yet, use a timed macro (or cron job, which you can set up easily with cronnix) to launch the script in the wee hours. This assumes that each computer will be turned on when the script executes.
Additional notes:
- Assuming that different computers will have different user accounts, you will need to specify the other user’s username and password in the “please enter the address” dialog that appears when first running the script. The URL format looks like this:
eppc://username:password@machinename.local
I’m not sure how to deal with spaces in the computer name (perhaps a backslash \ before the space–my machines all have one-word names; you can change the computer’s name in System Preferences : Sharing). - Likewise, it should be possible to sync libraries between two user accounts on a single machine using the above format. This probably requires that both users are always logged in (using Fast User Switching).
- This script only works for one host and one client. It should be possible to modify it to deal with multiple clients. I will leave that as an exercise for the reader.
Update With recent versions of iTunes, this is all redundant. Although it’s not entirely automated, there is a much simpler way to deal with this problem.
As above, treat one Mac as the host and one as the client. On the client, go into Preferences:Advanced and make sure that “Keep iTunes music folder organized” and “Copy files to iTunes music folder when adding to library” are both unchecked. This is important.
Make sure the host’s disk is mounted on the client mac. Again, in iTunes, select the menu item “File:Add to Library…” and select the music folder on the host disk. This will scan the entire directory and add all the files to the client’s iTunes database. The client’s database will need to be updated whenever new files are added on the host (new files should only be added on the host); to do this, just repeat this process. It takes a few minutes.