Skip to content

Instantly share code, notes, and snippets.

@szhu
Last active March 26, 2018 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szhu/846624a01d7a322e730ab2d9db0a9b04 to your computer and use it in GitHub Desktop.
Save szhu/846624a01d7a322e730ab2d9db0a9b04 to your computer and use it in GitHub Desktop.
Small daemon to send documents to your Kindle and eject it every time it's connected
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.interestinglythere.sendtokindle</string>
<key>StartOnMount</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>-c</string>
<string><![CDATA[
#!/bin/bash
set -eou pipefail
SRC="$HOME/Calibre Library/Send to Kindle"
DST="/Volumes/Kindle/documents/Sent to Kindle"
DST_DEVICE=/Volumes/Kindle
test -e "$SRC"
test -e "$DST"
IFS=$'\n'
for file in $(find "$SRC" -mindepth 1); do
osascript -e 'display notification "'"Sending $(basename "$file")"'" with title "Send to Kindle"'
mv "$file" "$DST"
done
unset IFS
diskutil eject "$DST_DEVICE"
osascript -e 'display notification "Sync Finished" with title "Send to Kindle"'
]]></string>
</array>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment