Skip to content

Instantly share code, notes, and snippets.

@bwmorales
Last active August 24, 2019 16:38
Show Gist options
  • Save bwmorales/2407fcbf89a9e95fce7566544e141239 to your computer and use it in GitHub Desktop.
Save bwmorales/2407fcbf89a9e95fce7566544e141239 to your computer and use it in GitHub Desktop.
Because this one time I was really stupid and let a client tell me to try backing up /Applications on macOS.....
#!/bin/bash
backupAndSyncConfig="Library/Application Support/Google/Drive/user_default/sync_config.db"
removeDataKeys="DELETE FROM data WHERE data_value IS '/Applications';"
removeDataValues="DELETE FROM data WHERE data_key IS '/Applications';"
loggedInUser=$( scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
for user in $(dscl . list /Users UniqueID | awk '$2 >= 500 {print $1}'); do
userHome=$(dscl . read /Users/"$user" NFSHomeDirectory | sed 's/NFSHomeDirectory://' | grep "/" | sed 's/^[ \t]*//')
sqlite3 "${userHome}/${backupAndSyncConfig}" "$removeDataKeys"
sqlite3 "${userHome}/${backupAndSyncConfig}" "$removeDataValues"
done
for process in $(ps aux | grep -v grep | grep "Backup and Sync" | awk '{print $2}'); do
kill $process
done && sleep 45 && \
open "/Applications/Backup and Sync.app"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment