Applescript to run when iPhone connects/disconnects

Solution 1:

Is this sort of what you're looking for?

Usbmux

...usbmuxd then watches for iPhone connections via USB; when it detects an iPhone running in normal mode (as opposed to recovery mode), it will connect to it and then start relaying requests that it receives via /var/run/usbmuxd – this is to say, usbmuxd is the only thing that actually speaks USB to the iPhone.

http://theiphonewiki.com/wiki/Usbmux

Solution 2:

The first part of the answer is fairly easy.

  • Save your AppleScript as a droplet or app to the filesystem.
  • Select that app in Image Capture as the tool to open when a specific iOS device is connected.

Depending on your need, you can have a suite of scripts, one for each device (or device role) or do some processing to determine the name of the attached device and handle things with logic from within AppleScript.

The second part might need a second watcher program that polls the USB ports and then triggers whatever script you wish to run.