Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

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.

share|improve this answer
    
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
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.