Tim’s
Bandwagon

How to run a script to do useful stuff when you plug-in your iPod


– This is a Folder Actions AppleScript that triggers an
– event when a disk (like an iPod) is mounted by the
– System. I use it to run a compiled Automator workflow that
– backs-up my Keychains, and copies my GTD lists to the
– iPod notes folder.
– 
– To run it you should tweak the script accordingly, and add it
– as a Folder Action to the “/Volumes” folder. It isn’t
– exactly obvious how to do this, so here’s how:
– 
– 1. Open the “Folder Actions Setup” app.
– 2. Click the ‘+’ button to add a new Folder Action.
– 3. The “/Volumes” directory is hidden from view. Don’t click
–    anything, type “/Volumes” to get to it.
– 4. Add this script as a Folder Action.

on adding folder items to thisFolder after receiving addedItems
    set volumeName to “Tim Brayshaw’s iPod” – change this!
    repeat with addedItem in addedItems
        if the displayed name of (info for addedItem) ¬
            is equal to volumeName then
            volumeMounted()
            exit repeat
        end if
    end repeat
    – System Events seems to keep file references open to each of
    — the “addedItems” above, this means you can’t eject these
    — volumes. This bodge quits System Events, so you can eject
    — the added volumes. (System Events gets launched immediately
    — again.)
    quit application “System Events”
end adding folder items to

on volumeMounted()
    tell application “Finder”
        open application “Update iPod”
    end tell
end volumeMounted

This should world for other devices like USB thumbdrives, external FireWire disks, Digital Cameras etc. I futzed around trying to figure out how to do this with launchd, but gave up. If anyone knows a better or other way, post a comment!

I’ve found this useful because it’s removed some backup anxieties, and means I’ve always got my shopping and out-and-about errands lists (and so on) with me when I’m away for the computer. There’s probably a better way of doing this, but it took me an inordinate amount of time to figure it out, so I thought I’d post a code snippet here for like-minded dabblers.

7 Comments

  1. Hi Tim,

    That’s timely, as I’ve just taken delivery of my first iPod (yay!). Does your script require Tiger, or will it run under Panther?

  2. I’ve only tried it with Tiger, although it should work with Panther too.

    Be warned, though: I’ve had problems ejecting disks after the computer has slept, then woken. (Although manually quiting the “System Events” process using the Activity Monitor app seems to allow you to eject the disks again). Definitely not ideal, but almost good enough!

  3. Double warning!(!) I’ve stopped using this while I figure-out the ejecting problem. Tips welcome.

  4. […] After reading his post How to run a script to do useful stuff when you plug-in your iPod, I was able to adapt this to use the “export to iPod” feature of VoodooPad […]

  5. Ok do you have any more descriptive instructions on how to use this? because I am not experienced using scripts but it sounds like an awesome idea

  6. you suck tim

    you dont know anything

    you are such a fuckin loser

  7. Hey ‘tim sucks’ — you fuckin rock! I KISS YOU!

Leave a Comment

Your personal information

Your comment