Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@boneskull
Last active August 20, 2019 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boneskull/6d1fc763fa6da4b53c61 to your computer and use it in GitHub Desktop.
Save boneskull/6d1fc763fa6da4b53c61 to your computer and use it in GitHub Desktop.
rsync stuff to a different directory on file changes (Mac OS X)
#!/bin/bash
# Get fswatch: brew install fswatch
EXCLUDES_FILE="/tmp/syncer-excludes.txt"
SOURCES=( "/path/to/folder/to/watch" )
EXCLUDES=(
"*.vmwarevm"
".DS_Store"
"Icon\r"
".dropbox"
".dropbox.attr"
)
DEST="/path/to/destination/folder"
printf -- '%s\n' "${EXCLUDES[@]}" > ${EXCLUDES_FILE}
for SOURCE in ${SOURCES[@]}; do
fswatch "${SOURCE}" "echo \"`date +%H:%M:%S`: Changes detected in ${SOURCE}; syncing to ${DEST}\" && /usr/local/bin/rsync -ru --stats --links --copy-unsafe-links --delete --exclude-from=${EXCLUDES_FILE} \"${SOURCE}\" \"${DEST}\"" &
done
wait ${!}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Debug</key>
<true/>
<key>Label</key>
<string>org.hiller.syncer</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/path/to/hook-line-and-syncer</string>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/hook-line-and-syncer.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/hook-line-and-syncer.log</string>
</dict>
</plist>
@boneskull
Copy link
Author

Update the plist to be the path to the script. You can use launchctl load /path/to/org.hiller.syncer.plist to automatically run this script at boot.

@boneskull
Copy link
Author

(also update whatever path(s) you want watched, and your destination folder in the bash script)

@boneskull
Copy link
Author

I use this to work outside of Dropbox (which has case-sensitivity problems) then rsync my crap into the Dropbox dir.

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