Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 have a flash drive, let's name it FLASH.

I want, when on my mac, when FLASH is plugged (and automatically mounted), execute a specific script and make ~/Documents to be automatically copied to /Volumes/FLASH/Documents (mac mounts drives at /Volumes).

This same drive, FLASH, (with this new Documents folder added before with the mac situation), when plugged in an Ubuntu machine, I want it to automatically copy FLASH/Documents to ~/Documents (or automatically execute an script, after mounting).

How should I do this in these different scenarios? I don't want to use third party applications for this, I prefer using core/builtin tools available in both platforms.

share|improve this question
up vote 1 down vote accepted

Use a launchd item using the StartOnMount key!

# example launchd plist file using StartOnMount key
open -e /System/Library/LaunchDaemons/com.apple.backupd-attach.plist

Further information:

share|improve this answer
This is great @jon. Welcome to StackExchange network. :) – Somebody still uses you MS-DOS Nov 4 '11 at 12:52

On the Mac, use Do Something When, a free software which triggers actions when you mount/unmount a drive.

On the Linux side, udev can run an external program when a disk is inserted (see e.g. How to be notified when a USB device was plugged?).

share|improve this answer
I've update my question, I don't want to use third party applications. Thanks for the answer though. – Somebody still uses you MS-DOS May 13 '11 at 22:15

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.