Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently writing my thesis at a big company, with an even bigger corporate firewall. So I've to save my work on an USB flash drive. Now I'm searching for a backup solution for that flash drive and don't want to do this manually. Does somebody know how to run a program / bash file when this specific USB device id connects to my computer so I can automate the rest of the process?

share|improve this question
up vote 0 down vote accepted

Create a LaunchDaemon (if you want the script to run independently of who's logged in) or LaunchAgent (if you want it to run inside the current user's session), with the StartOnMount key set to true. The script will be run anytime any volume mounts, so you'll need to start the script with something to detect your particular drive -- it could check by name (i.e. look for "/Volumes/My Backup Drive"), by a contained file (look for /Volumes/*/.backupTarget), or whatever. If you want some sort of hardware ID, your best bet is probably the ioreg command.

share|improve this answer

Your Answer


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.