5

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.

Caleb
  • 70,105

2 Answers2

1

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 in?).

Hai Vu
  • 1,201
1

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:

jon
  • 26
  • 1