American in Spain

Applescript to Send Songs to a Shared iTunes Library

May 31, 2007

Note: To all of you that have found this post while searching for a way to copy songs FROM a Shared iTunes Library, read this. If you want to copy TO another iTunes library, then continue.

In my search for a solution to this problem, I have found that many other people find themselves in similar situations. Here's a basic statement of the problem:

  • I have a laptop that I use at home but often take with me
  • I have a desktop at home with much more storage space than my laptop
  • I want to maintain all of my music on my desktop, but keep a subset on my laptop for playing when I'm not on my home wi-fi network.

Add to that my additional needs that...

  • I don't even have a monitor, mouse or keyboard connected to my desktop machine
  • And therefore, I want to control adding music to my library completely from my laptop

The best solution that I was able to find from searching the internet is this dude that has his laptop using an iTunes library on a shared network drive on his server. Then, when he leaves the home network, he has a script to switch to a local library. The worst thing about that setup is that it could be complicated to add songs from your network server to your local library before disconnecting.

My solution is to add new songs to my local library, and then when I tire of them or need to free up some disk space, I send them to my shared library on the server. This way, I always have my newest music on my laptop, but if I want to listen to some older songs while I'm at home, I can connect to the shared network library inside iTunes. The trick to my solution is how I send the songs to the shared library, hence the title of this post.

I have written an applescript that will...

  1. Take the tracks I have selected in iTunes
  2. If any album art has been downloaded from the iTunes Store, and is therefore not embedded in the song file, embed album art into the song file
  3. Copy the files to a staging directory on the network server
  4. ssh to the network server and run an Automator script that...
    1. Takes all the files in the staging directory
    2. Adds them to the iTunes Library, which copies the files
    3. Deletes the files from the staging directory

The Script

This is the script that I have on my laptop. If you download it, the part at the top is all that you should have to change. Applescript

You may download the script here: Copy Songs To Archive Server.scpt

If you put the script in your "~/Library/iTunes/Scripts" directory, it will be available from the menu bar when you are in iTunes.

Note that, for the ssh to work without prompting you for a password, you must set up ssh key pairs. There are plenty of pages around telling you how. This is not one of them.

The Automator Workflow

This the Automator workflow that runs on the server. You have to export it from Automator to be an application.

Automator Workflow

You can download mine ( if you want, or you can just create your own from the above screenshot.

Fitting it all together

Obviously, you'll have to edit the applescript to point to the correct staging directory, server, and location of the Then you just select the songs you want to copy in iTunes on your laptop, choose "Copy Songs To Archive Server" from the script menu, and watch them appear in the shared library. You can then delete them from your laptop if you want, and still listen to them over the network. I wouldn't do more than 50 or 100 at a time, though. I've had "This script has stopped responding" timeout errors when I try more.

Questions and Comments

If you're too lazy or paranoid to sign up and leave a comment here, you can email me at erikwordpressplugins -at- gmail. Happy song archiving!