So, a little context.
At home, I’ve got a Mac mini running as a media server. I keep all my music on there instead of my Macbook or Thinkpad (eww, Windows, I know, but it’s for work) because it’s got a ginormous hard drive specifically for that purpose. (I use Simplify Media to stream said library to any computer I happen to be on).
Just as a side note though, this will work for anyone using two computers, one on which the iTunes library is maintained and one where the media files are downloaded. The machine with the iTunes library does not necessarily need to be up and running on all the time. Also, this solution is specifically for a scenario in which an OS X machine is the target with the iTunes Library on it. If you’ve got your Library one a Windows machine (eww, Windows), sorry, you’re on your own. :)
During the week, the computer I happen to be on, sadly, my work computer. This is also the time when I might read a random music blog and download an mp3, or a friend might send me some songs via email or IM or what-have-you. So if I’m at work, where do these end up? Right, on my work computer. Far, far away from my iTunes library at home.
# This is where Dropbox comes in
Dropbox, for the uninitiated, is a fantastic little app that allows you to sync a folder between all your computers, as well as their server, “in the cloud”. God, who else is starting to hate that phrase, amirite? Anyway. You get 2GB free, you can buy some more if you want. So I have Dropbox installed on the laptops and the mini, and when I download a song on one of them, I just stick it right in the Dropbox folder, and when I get home, there it is sitting, on that computer, waiting to be imported into iTunes. Lovely!
Except I am lazy and forgetful and never remember to do that part. And the songs sit in the Dropbox, unlistened to, collecting dust, taking up space in my Dropbox.
# This where iTunes 9 comes in
With iTunes 9 we finally, finally, got a feature that users have wanted, like, FOR-EV-ER. A watched folder. Sort of. Well, it works, but it ain’t very flexible. Under your iTunes Music (or iTunes Media) folder, there’s a folder called “Automatically Add to iTunes”. Does just what it says on the tin. Put an mp3, or folder full of ‘em, into this folder, and blammo, there they are in your iTunes library. Nice.
So, now I’m thinking, how can I make this work with Dropbox, and get around that laziness/forgetfullness problem?
# What didn’t work - Symlinks
So the first thing I tried was symlinking* the iTunes special watch folder to a folder inside of Dropbox. So I moved the “Automatically Add to iTunes” folder inside of Dropbox, and inside of the iTunes Media folder, placed a symlink with the same name linking to the folder.
That didn’t work.
iTunes didn’t recognize anything placed in the folder. Seems it will only recognize things dropped into the appropriately named folder inside the iTunes Media folder. No ifs, ands, or buts. D’oh.
So I recreated the folder and tried placing a symlink to the folder I’d made inside Dropbox inside of it.
That didn’t work either.
iTunes actually tried to add the symlink itself, and not recognizing it as a proper format for iTunes, placed in a folder called “Not Added”.
:(
So the next thing I tried was to leave the iTunes special folder alone, and symlink to it from Dropbox. This got me soooo close. See Dropbox, unlike iTunes, actually does play nicely with symlinks. Most of the time.
I created a symlink to the special watched folder from within iTunes. Dropbox then proceeded to create similarly named folders on my other computers. When I added a file to this folder on a local machine, it synced to Dropbox, and back down to the folder via the symlink. Success! Almost! See, after iTunes adds the file to its library, it cleans up after itself and removes it from the folder. Only, Dropbox doesn’t see that it’s been deleted because the actual symlink file inside the Dropbox folder hasn’t been modified, just the folder it points to**. So Dropbox doesn’t delete the file from the server or the other machines. So close!
*If you don’t feel like opening up Terminal every time you need to make a symlink, there’s this contextual menu extension: SymbolicLinker.
**Dropbox does recognize that it’s been deleted upon restart, but that’s annoying.
# OK, screw the symlinks, let’s just try moving the files
The it occurred to me, I could use launchctl to create a deamon that would monitor a folder for files added to it, exactly what I wanted. So I ditched the symlink inside of Dropbox, and simply created a folder there. I then wrote a simple little bash script to move the contents of that directory into the proper one in the iTunes folder.
#!/bin/bash
/usr/local/bin/growlnotify -n "Auto Add to iTunes" -a iTunes -m "Moving to iTunes Folder"
cd "/Users/[USERNAME]/Dropbox/Automatically Add to iTunes/"
mv * "/Users/[USERNAME]/Music/iTunes/iTunes Media/Automatically Add to iTunes"
/usr/local/bin/growlnotify -n "Auto Add to iTunes" -a iTunes -m "Moved to iTunes Folder"
So, obviously, you’ll want to replace [USERNAME] with your own, and “iTunes Media” with “iTunes Music” if that’s how yours is named. And if you don’t have Growl + growlnotify installed (or you prefer not to have growl notifications for this) go ahead and remove the lines referring to growlnotify.
Download the shell script here and place it wherever you like to keep your scripts (I like ~/Library/Scripts). Open up TextEdit, or your preferred editor, and open the file and edit it as I mentioned above and save it. Now open up Terminal and navigate to where you saved the file.
cd Library/Scripts
Now make the file executable:
chmod a+x autoitunes.sh
If you’d like to test out that it works, place a file in the Dropbox auto-add folder you created, and run the script manually:
./ autoitunes.sh
Any file you placed in there should be moved to the iTunes special folder and removed from Dropbox.
Now, we have to get this little script run whenever a file is added to our folder. For this we’ll use something launchd. Don’t worry, we won’t have to mess with launchctl for this, there’s a neat little GUI for it called Lingon. Download and install that app and open it up. We’ll use this to create the daemon that will watch our folder and run the script.
Start up Lingon and click New. Select which type of daemon you’d like to create, I chose My Agents since Dropbox is only running when I am logged in anyway.

Now we create the agent. Step 1 is to give it a name. This can be pretty much anything you want, as long as it’s unique. I called mine “com.jessbrandi.AutomaticallyAddToiTunes”.

Next tell the agent what to run. Click Choose and browse to the shell script you saved and select it.

Finally, tell it when to run. We want it to run files are added to the folder we created within Dropbox, so in the last box click Path and navigate to it. I also selected at system start up, for good measure, in case of some sort of crash (what? OS X crash?) or something.

Click save, exit and reboot.
That’s it! You’re done! Now if you add an mp3 or video to the folder in Dropbox on any machine, it should automatically be added to iTunes!
Try it out. Find an mp3 (on the machine without the library):

Save it to the Dropbox:

As soon as Dropbox downloads it, it’s moved:

And iTunes takes care of the rest. The mp3 should now be in your iTunes Library.
One last thought on notifications, I added the Growl notifications, but they’re totally optionally. And as the script is being run on the target machine, that’s where it will show up, not on the machine you downloaded the original media file on. You should, however, get a notification from Dropbox on that machine that the file has been removed.
Please let me know if you have any comments or questions, or a better way to do this!