Last active
March 24, 2019 14:21
-
-
Save brokensandals/f3c6d1dba768821dac9eff380c3fbf12 to your computer and use it in GitHub Desktop.
script & launchd config for backing up Evernote to git repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
backup_dir=/Users/jacob/Backup/evernote-html | |
# thanks to http://veritrope.com/code/get-note-links-in-evernote-for-newly-created-notes/ for how to wait for sync to finish | |
osascript <<END | |
with timeout of (30 * 60) seconds | |
tell application "Evernote" | |
synchronize | |
repeat until isSynchronizing is false | |
delay 10 | |
end repeat | |
end tell | |
end timeout | |
END | |
if [ $? -ne 0 ]; then | |
osascript -e "display notification \"Failed to force synchronization.\" with title \"Evernote Backup\"" | |
exit 1 | |
fi | |
cd $backup_dir | |
git rm -r . | |
osascript <<END | |
with timeout of (30 * 60) seconds | |
tell application "Evernote" | |
repeat with curNotebook in (every notebook) | |
if (count of notes of curNotebook) > 0 then | |
set notebookBackupDir to ("$backup_dir/" & (name of curNotebook)) | |
do shell script ("mkdir -p " & notebookBackupDir) | |
export (find notes ("notebook:" & (name of curNotebook))) to notebookBackupDir format HTML | |
end if | |
end repeat | |
end tell | |
end timeout | |
END | |
if [ $? -ne 0 ]; then | |
osascript -e "display notification \"Failed to export notes.\" with title \"Evernote Backup\"" | |
exit 1 | |
fi | |
cd $backup_dir | |
git add . | |
git commit -m "$(date) from backup script" | |
if [ $? -eq 0 ]; then | |
changes=$(git show --stat HEAD | grep changed) | |
else | |
changes="No changes." | |
fi | |
git gc | |
osascript -e "display notification \"$changes\" with title \"Evernote Backup\" subtitle \"HTML export completed.\"" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>Label</key> | |
<string>net.brokensandals.evernote.backup.html</string> | |
<key>Program</key> | |
<string>/Users/jacob/dotfiles/bin/backup-evernote-html.sh</string> | |
<key>StartCalendarInterval</key> | |
<dict> | |
<key>Hour</key> | |
<integer>4</integer> | |
<key>Minute</key> | |
<integer>0</integer> | |
</dict> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated 2019-03-24 to prevent script from failing when it encounters an empty notebook, and to add notifications so that such errors are not swallowed silently.