Sync PDF Folder to Kindle

A quick hack to automate syncing my "to_read" PDFs folder on my desktop with a folder on my Kindle DX. This hack comes in two parts, both of which will require editing to make it fit for you. If you make updates to this hack, let me know and I'll incorporate them here. Also, I will update this hack over time so follow me on Twitter to find out about updates. If you encounter any errors and would like some help, feel free to email me.

Part 1 - Bash script

File: syncToReadToKindle
Purpose:
This script is run whenever launchd detects that a new Volume has been mounted. It checks to see if the Kindle volume is present and if so it:

  1. Syncs a directory from your computer to the Kindle's documents folder.
  2. Uses growlnotify to let you know when this is done.
  3. Ejects the Kindle volume so you do not have to do it manually.

Code:

#!/bin/bash                                                                                                                                                                       
if [ -x /Volumes/Kindle ]
then
     rsync -arv --size-only --delete ~/Desktop/to_read/ /Volumes/Kindle/documents/to_read/
     if [ -x /usr/local/bin/growlnotify ]
     then
         /usr/local/bin/growlnotify -m "Kindle Sync Complete"
     else
         echo "Kindle Sync Complete"
     fi
     diskutil eject /Volumes/Kindle
fi

Making it work:

  1. Make sure that the paths of your desktop directory (in my case ~/Desktop/to_read/) and Kindle directory match your directory choices.
  2. Copy the file to some permanent place and make sure that it is set to be executable (i.e. chmod a+x syncToReadToKindle).

Part 2 - Launchd Plist

File : com.nirmalpatel.KindleToRead.plist
Purpose:
This plist tells launchd to run the bash script from Part 1 any time a new volume is mounted. The bash script takes care of checking if the Kindle volume is mounted.
Code:

<?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>com.nirmalpatel.KindleToRead</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/nirmal/bin/syncToReadToKindle</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StartOnMount</key>
	<true/>
</dict>
</plist>

Making it work:

  1. Open it and edit the part that says /Users/nirmal/bin/syncToReadKindle to point to the download location of the script from Part 1.
  2. Move this file over to ~/Library/LaunchAgents on your machine.