Skip to content

Instantly share code, notes, and snippets.

@jstrobel
Last active August 29, 2015 13:57
Show Gist options
  • Save jstrobel/9756702 to your computer and use it in GitHub Desktop.
Save jstrobel/9756702 to your computer and use it in GitHub Desktop.
Backup when USB-Drive is mounted

##Start backup when USB-Drive is mounted##

Hint: This documentation is for MacOS only!

  • Start Automator
  • Create a new "folder action"
  • Choose "other" in the Folder-Dropdown
  • Hit: CMS+Shift+G on the keyboard
  • Enter Folder Location: /Volumes
  • In the Library on the left: "Utilities" -> Start AppleScript
  • Copy this AppleScript to the code-box
property USBName : "USBDrive-Home"

set currentDisks to paragraphs of (do shell script "ls /Volumes")

if (USBName is in currentDisks) then
	do shell script "/Users/jstrobel/tools/backup_usb_home.sh"
end if
  • Change "USBDrive-Home" to the name of your USB-Drive
  • Save

The Backup-Script:

rsync -rlptg /Users/jstrobel/Documents/projekte "/Volumes/USBDrive-Home/" --exclude-from=/Users/jstrobel/.rsync/exclude
diskutil unmountDisk force "/Volumes/USBDrive-Home"

You see a little "gear" in the taskbar, when the Script is running. After it is finished the USB-Drive will unmounted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment