iTunes Home Sharing feature is a great way to listen to content in other iTunes libraries around your house. It’s also pretty simple to copy individual songs. In my case though neither of these options are quite good enough.
I am a multiple Mac household. I have a MacBook Pro for work, my wife has a MacBook and my kids and I share an iMac as the family computer. I was keeping my iTunes library on my iMac but since I’ve begun using my MacBook Pro I’ve wanted to have my music there.
What I really want to do is have an easy way to keep both the iTunes library on my iMac and MacBook Pro synchronized. After doing some searching around I found that it’s pretty easy to do with some features built right into Mac OS X.
At the end of this article you should be able to sync your iTunes library from one Mac to another.
Update : This problem has been addressed with iTunes Match. iTunes Match is a pretty low cost way to keep your iTunes libraries in sync across all of your iDevices.
Note that I only intend to do a one way sync. This means I’ve picked one of my two libraries to act as the master library that will sync to the second library. It’s possible to sync both ways but I feel it is safer to just go one way.
The first step is to ensure that each Mac can see each other. Open up the Finder window on each Mac and look in the sidebar (the left side of the Finder window). You should be able to see the other machine. If you see it you have file sharing enabled. If you can’t, you need to enable file sharing following the steps below.
Enable File Sharing
Sync iTunes using Automator
Ok, so now that you have your two machines seeing each other the next step is to actually transfer your library from one machine to another.
Before we get to that, let’s think about the tasks we need to accomplish. For this application we need to do the following:
- Connect Mac A to Mac B
- Copy the iTunes Library from Mac A to Mac B
- Disconnect Mac M from Mac A
In order to do this we’re going to turn to some UNIX shell scripting and Automator. Don’t worry if you don’t know what UNIX shell scripting is. It’s super easy and will help you realize the power underneath the hood of your Mac.
Open Automator and select that you want to create a new Workflow. We can save this as an application later.
Next, we need to setup our Automator Workflow. Let’s think back to the steps we identified. The first step is Connect Mac A to Mac B. We can do this with the Get Specified Servers Action. Find it from the list of actions and drag it over to the Workflow window.
Now that it’s here, you need to add the target Mac’s file share information. Select Add and then select the computer from the list. Then append the name of the user on the target machine that has the iTunes library. In my case it’s Dad so I add /Dad to the name of the server and click Ok.
The next step is to actually connect to that server. Grab the Connect to Servers action and drag it below the last action. Once the connection is made, we run the command that actually copies the files. For that we turn to a powerful UNIX command rsync.
Drag the Run Shell Script into your workspace and attach it below the last action. Now, you can enter the command that performs the copy. Copy and paste the following.
rsync -av --force --delete --dry-run ~/Music/iTunes /Volumes/Dad/Music > ~/Documents/iTunesSync.log
The rsync utility is essentially a backup tool used to keep directories synchronized. Unlike a simple file copy rsync looks at things like the size and date of a file to decide whether or not it should do the copy. The first time you do your sync it will take a while. After that, every time you run rsync it will only copy over the files that change.
So you know what’s going on, let’s walk through each of these options. The -av option tells rsync two things 1) this is archive mode which tells rsync to behave in a way that works well for backups and 2) be verbose and tell us what you are doing. The –delete switch will remove files from Mac B that are no longer on Mac A. This way if you remove files in your iTunes library rsync will reflect those deletions in the other iTunes library.
The switch –dry-run is your safety net while we’re building this script. With the –dry-run option we won’t actually copy the files. When we are all done, we’ll remove the switch.
The next two parameters are the source path and the destination path. The source path is where your main iTunes library is. Typically it’s in your home directory (~) in Music/iTunes. Change this as needed. The destination path is the location where we are sending this iTunes library to. For me it is /Volumes/Dad/Music. For you it is whatever directory you connected to when you ran the Get Specified Servers Automator action.
Finally we are going to send the output of rsync to a file so we can review it later to make sure everything worked ok.
This was the most complicated part of the Workflow. The next and final step is to disconnect the two computers. Drag the Eject Disk action and attach it below the Run Shell Script action.
At the end of the process you Workflow should look like this.
Testing the Workflow
Now that you’ve built the workflow, let’s test it. You’re going to run the workflow and look at the log file to see if things look ok. If everything is ok we can remove the –dry-run switch
Note that what we’re doing could be dangerous! If you setup the rsync command incorrectly you could end up deleting your iTunes library. This is why we use –dry-run first. Make sure you have a backup of your library handy in case something goes wrong.We’re not responsible if you hose your music library.
Ok, with that bit out of the way, let’s run the test. Click the play button to run the automator workflow.
The first thing that may happen is you are prompted for a password. This is part of the network connection process. Choose the user name you use to login to the account with the iTunes library.
As Automator works through each step of the process, you’ll see it place a green check next to each action. The longest part of the process is going to be rsync. Remember though at this stage we are not actually copying files so this still should only take a few minutes to complete.
When everything is finished we’re going to look at the results. Open up your Documents folder and look for the files iTunesSync.log. Open that up in a text editor and look at what is going on. You should see a list of files that rsync is trying to copy. If this seems ok to you then you’re ready for a live test.
Remove –dry-run from the shell script. Now, save the Automator Workflow. Choose File->Save As. Then, place it somewhere you will remember it. I put mine in ~/Applications and change the File Format from Application. This will let you run it directly without first going into Automator.
Once it is saved, click the Play button again and go make a sandwich you’ll be waiting for a while.
If you want to tune in to what is happening you can do a little more UNIX-fu. Run the Terminal command. In the Terminal Window, go to the ~/Documents folder (or where ever you put your iTunesSync.log file) and type the following:
tail -f iTunesSync.log
This will let you watch what is happening as the Automator script runs.
That’s it. You’re now able to keep your iTunes libraries in sync. What I find really cool about this is it touches on a lot of more advanced things you can do in OS X. Automator let’s you fairly easily create your own programs to solve problems and UNIX shell commands which let you do some pretty powerful things.