Saturday, April 4, 2015

Automatically syncing Kindle clippings with Evernote

While looking for a code snippet I stumbled upon a certain hack I made a few years ago. This was back when I was first introduced to programming and Linux. I still remember reading about all the tech for hours to get it working. Thought it was worth documenting even-though I’ve since found a better solution.
One of the extensively used features on my Kindle is the text highlights. I wanted a way to automatically sync these clippings to Evernote so I could check them on the go through Evernote’s Android app.
Solution
  1. Detect the Kindle when plugged
  2. rsync clippings.txt to Dropbox’s public folder via a shell script
  3. Make a IFTTT recipe to sync My clippings.txt with Evernote
udev system is a way to handle peripherals such as usb devices. It’s your friend when you want to change the behavior when an usb device is plugged in. First thing we have to do is to find the device node of the Kindle. So hit fdisk -l to a terminal and find the relevant node id. It was sdc1 in for me.
Then we need to find some information to identify the kindle. Do this with
udevadm info --p $(udevadm info -q path -/dev/sdc)
This will put out a long list of information. ATTRS{idProduct}, ATTRS{idVendor} and ATTRS{serial} are the ones we are looking for.
Then make a new rule by creating a new file at /etc/udev/rules.d/ Make sure the file name starts with a number between 70 and 90. eg: 81-kindle.rules
Put the following line in your newly created file.
KERNEL=="sd?1", ATTRS{idVendor}=="xxxx", ATTRS{idProduct}=="xxxx", ATTRS{serial}=="xxxxxxxxxxxxxx", RUN+="/home/malithsen/bin/copy-kindle.sh
Replace ‘x'es with the relevant details from the previous command. Our copy-kindle.sh would look something like this.
#!/bin/bash
rsync -u "/media/Kindle/documemts/My clippings.txt" /home/malithsen/Dropbox/public/Kindle/
This script gets triggered every time we plug the kindle through our udev rule. Script will sync My clippings.txt which contains all the highlights to our Dropbox folder. Now setup IFTTT to sync My clippings.txt in Dropbox with Evernote. I’ve put together a recipe for this.
This worked pretty well, but then I found clippings.io which does a better job. Unlike the first method it doesn’t automatically copy clippings to Evernote. But once you upload the text it cleanly splits My clippings.txt to separate notes on Evernote. There are loads of other nice features too. Be sure to check it out.

No comments:

Post a Comment