I'm trying to figure out how to run an applescript when I connect and disconnect my iPhone with the USB cable.

So far, I think I can run an applescript when it connects by using Image Capture (setting "connecting this phone opens" to "other" and selecting the script).

I don't know how to run a script when the phone is disconnected however. Ideas?


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.

  • but not helps running the script when he disconnects the phone... – jm666 Apr 15 '13 at 17:28
  • @jm666 So true. I've clarified my half-answer :-) – bmike Apr 15 '13 at 19:25
  • any suggestions on how to create a watcher program? – elstgav Apr 15 '13 at 19:30

Is this sort of what you're looking for?


...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.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .