Tips, Tricks & Hacks for OS X

OK, not OS X related, but has me re-thinking a backup strategy for my iPhone.

devteam:

Here are some details on our latest version of PwnageTool 3.1.4 for Mac OS X which supports the 3.1.2 release of the iPhone software for iPhone 2G/3G/3GS and iPod Touch 1G/2G.

If you’re already jailbroken (by whatever means), you don’t need to mess around with DFU mode at all.  Just create (or get from a friend) your custom IPSW and Option-Restore (Shift-Restore on Windows) to it via iTunes.  Don’t enter DFU mode at all.  Please make sure you are restoring to the custom IPSW, not the stock one from Apple!  For best results, use the latest iTunes (9.0.1) — which includes a nice new application organizer.

This release allows your baseband to remain unlocked at 3.1.2, but it does not unlock a new baseband put there by restoring to official 3.1.x.  It is super important that people who need the unlock to understand they can keep it only by starting at 3.0 (or earlier) and updating solely to custom IPSWs that don’t update the baseband.  For those who have been onboard the “unlock train”, simply install ultrasn0w via Cydia once you’ve restored to your custom IPSW.  Don’t forget to turn off the “3G” setting in Settings->General->Network if you use T-Mobile in the U.S.A.

Note for 3GS users not already jailbroken and stuck at 3.1.x: this version of PwnageTool has a side feature to jailbreak your 3GS.  It uses a simple implementation of the usb control msg hole found by chronicdev, geohot, and our very own gray.  Now that the hole is public and in use, we expect Apple to close it by the next major firmware update. That’s why 3GS users need to get their ECID hashes for 3.1.x now, and need to stay onboard the “jailbreak train” in all future updates.  For more details on what this means, please see our earlier posts or ask in our comments section (moderated by the always helpful @angie and @confucious!).

For the early adopters who ran blackra1n and are having problems with mobilesubstrate, winterboard, diskaid, or ifunbox, you can install a custom .ipsw from PwnageTool to fix these issues.  That’s because all jailbroken devices accept a custom .ipsw created by PwnageTool.  (However, if you ran blackra1n on a 3G or 3GS that means you updated to stock 3.1.x, and the carrier unlock is now out of reach.  We’ll continue to work on a carrier unlock for the latest basebands, but the timeframe for such an unlock is unknowable.)

Note: If you use internet tethering on a carrier that doesn’t officially support it, you’ll lose it by going to 3.1.x.  Stay back at 3.0 until a hack for that is developed.

SUMMARY:

  • The iPhone 3GS is now supported out of the box in PwnageTool 3.1.4 (or if you have upgraded to 3.1.x in iTunes)
  • The iPod 2G is still supported in PwnageTool 3.1.4 but you must already be jailbroken (we’ll update this if there’s a big demand from non-jailbroken ipt2G owners)
  • The iPod touch 3G is NOT supported

DETAILS:

  1. GOLDEN RULE: If you are using a iPhone 3G or iPhone 3G(S) with ultrasn0w and rely on ultrasn0w to obtain cellular service then you should only update your device with an .ipsw that is made with the new PwnageTool. There are no second chances with this. You need to remember that PwnageTool will provide an upgrade path to newer versions of the iPhone software in the future.
  2. Please read all parts of this post before downloading and using these tools.
  3. Read items 1, 2 and 3 again and again.
  4. At the bottom of this post are the bittorrent files for the 3.1.4 capable version of PwnageTool.
  5. PwnageTool will work for the iPhone 3GS
  6. PwnageTool will work for the iPod touch 2G
  7. PwnageTool WILL work for Original iPhone (1st Generation), the iPhone 3G and iPhone 3G(S) and the iPod touch (1st Generation and 2nd Generation) but NOT the iPod touch 3rd generation.
  8. For 3G and 3G(S) users who are Pwned, PwnageTool is your key to updating in the future, just remember to never install an update directly from Apple, always use an .ipsw that has been created with PwnageTool.
  9. There is no Windows version of PwnageTool it is a Mac OS X tool only, we are not developing a Windows version of PwnageTool.

What’s a Baseband?

The ‘baseband’ is the generic nickname given to the internal components of the iPhone that handle the phone calls and Internet access. This ‘baseband’ is a tiny and unique independent computer system that runs inside your iPhone, it is separate to the main system that handles the applications (such as email and google maps) and it talks to the main part of the phone over an internal communications network.

Think of it like a cable modem or other peripheral that is attached to your home PC that needs occasional updates. When a software update is released and presented to you within iTunes the baseband is sometimes updated (to fix bugs or add new features).

The 3.1.2 update for the iPhone 3G and 3GS contains such an update, so running the vanilla updater straight away with iTunes will reprogram and update the baseband.

WHICH DEVICE DO I HAVE?

Read the description to identify your device, once you have correctly identified your device follow the specific instructions for that device as listed below.

SIM Free/SP Unlocked/Factory Unlocked iPhone 3G(S)

This applies if you bought your iPhone 3G(S) for $$$$$$$. This model of iPhone 3G(S) doesn’t have an Service Provider lock (aka factory unlocked) and you are able to put any SIM card into the phone and get service. Your phone is already unlocked so you do not need to worry about baseband updates, you can use PwnageTool to create an ipsw and then use this to update and jailbreak your phone.

SIM Free/SP Unlocked/Factory Unlocked iPhone 3G

This applies if you bought your iPhone 3G for $$$$$$$. This model of iPhone 3G doesn’t have an Service Provider lock (aka factory unlocked) and you are able to put any SIM card into the phone and get service. Your phone is already unlocked so you do not need to worry about baseband updates,  you can use PwnageTool to create a 3.1.ipsw and then use this to with iTunes to upgrade and jailbreak your phone.

iPhone 3G

Use PwnageTool to do the magic and then restore with iTunes using your newly created .ipsw

iPhone 3G(S)

Use PwnageTool to do the magic and then restore with iTunes using your newly created .ipsw

iPhone 2G (1st Generation)

Use PwnageTool to do the magic and then restore with iTunes using your newly created .ipsw ‘nuff said, you don’t need to worry about anything, the baseband will be unlocked, the phone jailbroken.

iPod Touch 1G (Original iPod Touch)

Use PwnageTool to create a firmware image and restore with that .ipsw using iTunes.

iPod Touch 2G

Use PwnageTool to create a firmware image and restore with that .ipsw to your already jailbroken device using iTunes.

iPod Touch 3G

At this time PwnageTool does not support this device.

Official Bittorrent Releases -

  • PwnageTool 3.14 Torrent
  • PwnageTool_3.1.4.dmg.5122330.TPB.torrent
  • SHA1(PwnageTool_3.1.4.dmg.5122330.TPB.torrent)= d9d44258ade35623ec71e83520943b6f4baa568a

Unofficial Mirrors

The following links are unofficial download mirrors, you download these at your own risk, we accept no responsibility if your computer explodes or if it becomes part of a NASA attacking botnet or even worse if your hands fall off mid-way during the use of these files. We do not check these links or archives and we accept no responsibility with regard to the validity of the files, or with other content these links provide or with the content that is on the linked site.  Always check the published SHA1 sums. We would prefer that you downloaded the official bittorrent release that is linked above, but you are welcome to try these if you really must. Mirror owners should email direct links only to blog@iphone-dev.org , please don’t place mirrors in the comments as they will be deleted.

If you’re on a mac, and you use bittorrent a lot, chances are you’re familiar with Transmission, a lovely little bittorrent client.  But did you also know you can control Transmission remotely from another computer?  (And it doesn’t even have to be a mac!)

# Setting up the server

Transmission has made this startling simple.  Just go into Preferences, and select Remote.  Check “Enable remote access”.  You should set up a username and login below if you have others on your local network you don’t want accessing your Transmission, or if you plan to access Transmission away from home (see below).  If the computer you’ll be accessing it from is a mac, you can turn on Bonjour for easy access.

# Accessing Transmission from another computer

Now on to the second computer, where you’ll be accessing Transmission from.  If it’s a mac and you have Bonjour bookmarks enabled in Safari, you should see a link for your Transmission remote.

If you’re second computer isn’t a mac, you’ll need to know the “.local” name for you remote machine — you can set this in System Preferences -> Sharing -> Computer Name -> Edit.  Now simply type that address into your favorite web browser appending the proper port number from above:

http://yourmachine.local:9091

Log in with the username and password you set up (if you set one up) and you should an interface very similar to the Transmission app!

From here, you can add torrents via URL or a torrent file you’ve already downloaded.  You can pause and resume torrents, control speed throttling and even see info on selected torrents.

# Setting up an app using Fluid or Prism

Want your Transmission remote to feel even more like an application?  You can use something called a Site Specific Browser (SSB) to create your own little app for that.

On OS X, I use Fluid, which uses the Webkit (Safari) rendering engine.

Download and install Fluid.  When you start fluid you’ll be prompted to create a site specific browser.  Copy and paste the URL from your browser (including the “/transmission/web/” into the URL.  Name it what you like and choose an Icon if you want (I just used the Transmission app’s icon, which happened to be installed on this computer as well).

Click create, launch now, and there you go.  You now have a Transmission Remote App.

If you’re using Windows or Linux, you can use the Prism app (which I mentioned in my post about accessing 1Password remotely) to set up a similar SSB.

# Access Transmission from your iPhone (or other mobile browser)

Transmission even has a nifty web interface just for the iPhone!  Simply navigate to the URL for the Transmission web interface from Safari and log in.

You can even create a psuedo iPhone app by adding a shortcut to the homescreen.

Now, I’m guessing the mobile interface would work on other mobile phones, but since I don’t have one, I can’t verify.

# Control Transmission away from home (Advanced)

This step is for optionally controlling Transmission while you’re away from home.  I actually find this to be particularly handy, if I’ve come across something I’d like to download while at work or away, but don’t want to run bittorrent on whatever network I’m currently on, and want the file to end up on the remote machine anyway.  This bit is a little more complicated, in order to proceed you’ll need:

  • (Unless you have a static IP) A dyndns account and dyndns updater installed on the remote machine.
  • Access to your firewall and router, and a knowledge of how to forward ports, and assign static IP’s within your NAT (assuming your device isn’t connected directly to the internet).

Setting up dyndns and port forwarding is a bit beyond the scope of this tip, so if you’re not familiar with how to do this, a little googling should point you in the right direction.

On your router, you’ll need to forward the Transmission web server port.  You can make the public port anything you like, but the internal port must match the number set in the Transmission Remote settings (the default is 9091).

While you’re away from home, you can use the dynamic host name you set up with dyndns to access your computer.  To try it out, type the address in the address bar as you did above, but replace the “.local” name with your dyndns host name.  If you made your public port something other than 9091, you’ll need to append that instead.

You can edit any bookmarks you made to the Transmission Web interface to use this new URL as well, but you’ll need to re-create your SSB’s and iPhone shortcut from scratch.

Now you can control your home Transmission from anywhere!

# Make sure it’s always running

One last note, the transmission app needs to be running for the web server to work, so if you just want to have it always running, right-click on the dock icon and select “Open at Login”.

Yep, that’s right, anywhere. Even Windows and Linux.

So you guys already know I’m a big fan of Dropbox right? If you didn’t, read up on my earlier post Dropbox + iTunes 9 = Automatically add songs to a remote copy of iTunes.

# You guys, 1Password is really rad

This tip is another neat little use for Dropbox using my favorite password manager: 1Password. So 1Password is an awesome app for OS X for keeping track of and generating your passwords. Note, it’s not free. But a little googling will find you a discount. Personally, I find this app (and the companion iPhone app) to be well worth the price. I use it to keep track everything, from logins to WiFi passwords to bank account numbers to software licenses. It’s a fine piece of software, plugs into your mac browsers, and is pretty darn secure.

So anyway, this tip assumes you’re already using 1Password. Now suppose you’ve got multiple computers, like me, and some of them (gasp!) aren’t even macs (I know!). But you’d still like to be able to access your passwords (securely!) from anywhere. As it turns out this, is extremely easy to do across macs using Dropbox. In fact, the fine folks at 1Password even wrote a very detailed explanation of how to do it. Another thing you should note, the 1Password app has what I consider a “reasonable” licence…you pay per user, not computer. So yes, go ahead and register that second mac with the same 1Password license. They’re cool with that. :)

OK, but then you’re at work or something, where maybe they force you to use Windows or something (ewww, Windows) or maybe Linux, who knows. And now you can’t remember your password to that one site you’d really like to login into right now. Whatever will you do?

Well, since you’ve probably already got Dropbox installed (since you can stick that pretty much anywhere), you’re in luck, thanks to a nifty little feature of 1Password called 1PasswordAnywhere. Navigate to the folder inside of Dropbox where you saved your 1Password agile keychain. The keychain will appear as a folder in Windows or Linux. Open up that folder and inside you’ll notice a file called 1Password.html.

Ohhh, what does that do?

Yup, a fully functional web app version of your 1Password database, fully password protected, usable from any computer that has a web browser. (You know, all of them.)

BIG CAVEAT: This database is read-only, so you can’t add or generate passwords via the web app.

# Prism: Turn that Web App into an actual App

Time for another little utility I’m a big fan of! This time it’s Prism, from Mozilla. Basically, Prism lets you turn web apps into pseudo-applications. And that’s what I decided to do with 1Password on my Windows laptop, since I couldn’t install 1Password itself.

Download and install Prism. Now we’re going to create an application for 1Password. Start up Prism and enter the URL for your new app, which will in this case be something like

file:///C:/Users/<yourusername>/My Dropbox/1Password.agilekeychain/1Password.html

You can just copy and paste the URL from the browser when you clicked that .html file earlier. Name it 1Password and choose where you want the shortcut located. I put it on my Desktop. You can even choose an icon for your App, I used this .png file I found upon the internets (© Agile Web Solutions, naturally).

Now you should have a shortcut to your 1Password app.

Open it up:

Ta-da!

# And when I say anywhere, I really do mean anywhere.

I previously mentioned the iPhone app for 1Password, which would let you keep your 1Password database synced to your phone.

But suppose, heaven forbid, you don’t have an iPhone? And say you’re using a computer that’s not yours and doesn’t have Dropbox installed, now what?

Don’t worry, Dropbox has a handy web interface, and since all your data is stored in the cloud, it’s available from any computer with an internet connection. Just head on over to the Dropbox website and navigate to the folder where you saved the keychain and find the html file, just as you did on your computer earlier. Click the link, and there’s your 1Password database, still protected with your master password.

Taking it even a step further, there are some add-ons for dropbox (sadly, Windows-only at this point) which will let you sync your Dropbox to a portable USB drive, DropboxPortable and DropboxU3 (for U3 drives). With your Dropbox sync’ed to your keychain, you can even access your 1Password db without an internet connection, by simply navigating to the 1Password.html file in your keychain and clicking on it.

Have any other ideas for accessing 1Password anywhere? Post a comment!

Update (12/13/09): Check out my new post on integrating 1Password into Chrome on Windows using Xmarks.

There are a whole lotta ways you could access your mac at home while you’re away and control the desktop.  OS X comes with a VNC server built-in, and you could also use the fabulous LogMeIn.  But I’ve found, when it comes to user interface, my favorite screen-sharing client is actually iChat.  The credit for this idea goes to @lukebussey.

# What’s nice about iChat

The thing I really like about iChat’s screen sharing is the interface to switch between desktops.

You get a little “Picture in Picture” type of window of the other computer, while the remote one is full-screened.  Simply click the mini-window and it will flip the two.  I like this a lot, as having the remote screen full-screened makes it A LOT easier to control.  (Sure, the other options allow you to full-screen as well, but the switching back-and-forth is not nearly as smooth.)

Secondly, in my experience, the iChat client seems tuned for slower connections, and feels a lot more responsive than either the built-in screen sharing software or LogMeIn.  Sure, you can tweak these settings in those apps too, but this seems to just work better out-of-the-box.

Thirdly, if you’re using a mac a lot, you’ve probably got iChat open most of the time anyway.  So you don’t need to have another program open to control the remote screen, or even a browser window, as you do with LogMeIn.

# OK, I’m convinced, how do I set it up?

So obviously, you’ll need iChat running on the home machine you want to access, but in order to make this work you’ll also need to install the Chax plugin.  At the moment, if you’re running Snow Leopard, you’ll need the Chax beta available here, and make sure you start up iChat via the Chax app.

You’ll also need a separate IM account for the server, but you won’t want to give just anyone access to it, so I recommend setting up a new account on your IM network of choice.  This is pretty easy for AIM, but for GTalk you’ll need a whole new Gmail account.  Let’s use AIM as an example.

For added security, I made the username for my new AIM account a randomly generated string from 1Password, you can use whatever you like to generate passwords.  This way, only I know the username for my home machine’s AIM, so no one else can add it to their buddy list.  (I generated a password for it the same way.)

Set up the account on iChat on the home machine.  Set this account to automatically login when iChat opens.

Click Security.  Select “Allow people in my Buddy List”.  Add your personal account (and any other accounts you’d like to give access to) to the buddy list.

Now click the Chax settings.  Check “Auto-accept screen sharing requests”.  For even more security, select options to only accept requests from yourself.

Make sure that iChat/Chax starts up at login by right-clicking the Dock icon and selecting “Options -> Open at Login.”  Now, on the remote machine, fire up iChat and add the AIM user you created for your home server.

Right-click on this user and “Ask to share <user>’s screen”.

Done!

As a side note, you can also set up the account on the home server to auto-accept file transfers and specify a download folder in the Chax settings in the same way you set up screen sharing.

So, how great is Time Machine, right? You already know. If you’re like me, you back up all your Macs to an external hard drive or Time Capsule or some such. It’s certainly saved my butt more than once, and I can definitely sleep better at night knowing that years’ and years’ worth of mp3’s and pictures and everything else is backed up, safe and sound, in case of catastrophe. I’ve got most of my media on a Mac mini that’s always on at home, always being backed up. But work and other documents live on my Macbook, which is often not at home. So it’s great when I’m sitting on the couch, I just open it up, Time Machine start’s spinnin’ and blammo, backed up. Nice. Except…I’m not sitting on the couch at home as often as I’d like. So if I want to back something up while I’m away from home, or even retrieve an older version of a document, I’m up a creek until I get back to the homestead. Which is a shame, because that big ol’ hard drive with all my data is sitting at home, lonely, collecting dust.

# Step 1: Accessing the Time Machine disk remotely

First off, this obviously isn’t going to work unless your Time Machine is always on, either as a drive connected to another mac, or a Time Capsule disk on your Airport. Secondly, it’s probably not directly connected the internet, it’s likely sitting behind a router (unless it’s a Time Capsule, but even then, it’s not directly accessible to the outside world by default). Thirdly, you probably don’t have a static IP Address with which to access it. So the basic strategy for making the Time Machine Disk available is this: First forward the afp (the network file sharing protocol on macs) port on your router to the machine with Time Machine disk. You’ll need to forward port 548 to the machine with the Time Capsule disk. I’m not going to go into detail how to do this, as it will vary depending on your router, and there are plenty of excellent resources and tutorials out there on the Googles that would do a much better job of explaining it. Important exception! If you’re using a Time Capsule or your disk is connected to an Airport, you won’t actually need to forward the port, as they are directly connected to the internet anyway. However, you will have to open the ports up for access outside of your home. Open Airport Utility and click “Manual Setup”. Click on “Disks” and then “File Sharing”. Check “Share disks over WAN.” Also, I’d advise turning OFF Guest Access to the disks and using a very secure password to access them, as this disk is now exposed to the outside world.

Next you’re going to need an address to access this disk from if you don’t have a static IP address. (If you do have a static IP, you can skip this step, obviously.) There are plenty of services that will provide you with a domain name for your dynamic IP address, personally, I use DynDNS. It’s free and they’ve got a reliable OS X client. Note, if you’ve just got a Time Capsule, and not an always-on mac to run this, you’ll have to update it manually when you’re home. But honestly, your IP probably isn’t going to change all that much, likely only when you restart your cable or dsl modem. At any rate, register for a domain name and you should now be able to get to your router from the outside world via “yourdomain.dyndns.org”. To test out the domain and the port forwarding, while you’re away from home, open Finder, click “Go” —> “Connect to Server”. In the dialog box that pops up, type: afp://yourdomain.dyndns.org/

If everything worked, your Time Machine disk should now be mounted on your desktop!

# Step 2: Switching Time Machine Disks

Now, while the Time Machine disk is mounted remotely, open the Time Machine preferences and change the disk by choosing “Select Disk”.

You should see the share located at yourdomain.dyndns.org (or your static IP, or whatever). Select that.

That’s it! Now you’re backing up to the remote disk! You can also enter the Time Machine app and restore from previous backups, just like you were at home. When you’re back home, however, you’ll likely want to switch back to the “local” disk, as syncing of the LAN is preferable (more secure, faster) than syncing over the WAN. Plus it seems sort of silly to send your data outside your router, just to send it right back. So when you get back home, you can just open Time Machine preferences again and select the “local” drive.

# Step 3: (Optional) Switching between local and remote Time Machines automatically

Part of the thing that makes Time Machine so great is that it’s always backing up, every hour, without any input from me. It just works. So obviously, switching back and forth between local and remote disks would hinder this. At this point, I went a-googling for a shell script that would switch Time Machine disks for me, and I stumbled across this site, with a very helpful tip on how to do this. Basically, you will need to capture the encoded value for each drive, and then create one script for each disk, which you’ll trigger when you switch networks. To launch the scripts, I use a little program called MarcoPolo, which can perform any number of actions when you change networks, such as a launch a shell script. While you’re at home and the local disk is selected, open up Terminal and type the following:

defaults read /Library/Preferences/com.apple.TimeMachine BackupAlias

Now open up TextEdit and paste the following:

#!/bin/bash defaults write /Library/Preferences/com.apple.TimeMachine BackupAlias 'disk'

but replace “disk” with the results from Terminal. Save this file wherever you like to save your scripts, for example, ~/Library/Scripts/time_machine_local.sh. Repeat these steps for the remote disk and call it time_machine_remote.sh. In Terminal, navigate to the folder where you saved the scripts and make them executable:

chmod a+x time_machine_local.sh
chmod a+x time_machine_remote.sh

Next, to get these to run automatically, download and install MarcoPolo (if you are using Snow Leopard use this beta). Set up two contexts “Home” and “Automatic” (or whatever you wish to call them). Set “Automatic” to be your default context. Set up automatic context-switching (I prefer to do this by WiFi SSID.) Next, set up some actions to trigger on context change. Select new ShellScriptAction and create one to trigger time_machine_local.sh when you arrive at the “Home” context. When you depart, trigger time_machine_remote.sh.

# Final Thoughts on Security

Is this secure? Well, no, not really. It’s password protected, but your backup disk is now open to the internet, and additionally, the transfers are not encrypted. If this is a concern for you, there are a couple things you could try (but I haven’t tried personally):

  • Set up a VPN at home (iVPN is one solution) instead of opening up the afp port and connect that way.
  • Set up an SSH server at home and tunnel the afp port through that.
  • ShareTool sets up a VPN over SSH and supports Bonjour.
  • ??? Do you have any better ideas? Let me know!

I’m still on the fence as to whether or not this is completely awesome or sort of useless.  The automatic icons for the Twitter accounts are kinda rad.  And the iSight/Screenshot —> TwitPic thing is definitely neat, though a tad insecure.  Playing around with it for now.

I didn’t know about most of these.

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!