The Fugue Counterpoint by Hans Fugal

6Jun/121

Code Reading on a Kindle

First, add this to your ~/.enscriptrc file:

Media: kindle 498 612 0 0 498 612

Now, here's a script (I call it kindlecode) to generate a pdf on stdout:

#!/bin/bash
enscript -Mkindle -E -p- "$@" | ps2pdf - -

Usage is something like this:

$ kindlecode *.{c,h} > /Volumes/Kindle/documents/foo.pdf

kindlecode in real life

28Dec/101

Asynchronous Kindle Transfer

I got a Kindle for Christmas, and it's pretty cool. Project Gutenberg never looked so nice. Getting ebooks onto it is pretty simple, just drag and drop. But that only works when the Kindle is plugged in, and I know I will think to download a book usually when the Kindle is not plugged in. Then I have to dig through my downloads folder (which makes a teenager's room look tidy) and find the ebook(s) and drag onto the Kindle. This needs to be automated.

It's actually pretty simple. First, make a "staging" folder. I put mine at ~/Desktop/Kindle. Then, fire up Automator and create a new "Folder Action". Choose /Volumes: whenever anything is added to /Volumes (e.g. when mounting a drive like the Kindle) it will execute. Add the action "Run a Shell Script". Here is my script:

src=$HOME/Desktop/Kindle
dst=/Volumes/Kindle

cd "$src"
while read item; do
  if [ "$item" = "$dst" ]; then
    rsync -av --remove-source-files "$src"/ "$dst"/ | logger -t Kindle
  fi
done

The --remove-source-files option to rsync makes this essentially a recursive move operation. So your staging folder will be empty once it has successfully synced—if you want to keep an off-Kindle backup of your ebooks you won't keep them in the staging folder. (You could omit --remove-source-files, but then if you deleted a book from your kindle it would just be put back the next time you plugged it in which would be annoying.)

The staging folder has the same directory structure as the Kindle, so put the documents you want to copy over into ~/Desktop/Kindle/documents/.