Using Safari's Reading List to Feed Instapaper
26 Mar 2012A week or so back, I started thinking that it might be nice to get away from using the Instapaper bookmarklet (which is great, don't get me wrong) and see if there was a way to use Safari's Reading List (which works on the iPad, iPhone, Mac, and presumably the PC) to send links to Instapaper.
This is about the Mac implementation, but presumably, a PC implementation would work similarly.
Getting the Reading List info to feed into Instapaper was surprisingly easy. I used Ruby, but you could certainly use pretty much any scripting language. The Reading List entries are stored in the Bookmarks.plist file that lives in your ~/Library/Safari directory. It's a binary plist, so you have to run a magic plist command on it to convert it into a text plist.
At that point, if you want to, you can throw that through a regular expression, or into a plist/XML parser to deal with it like an object.
You find the set of entries that define the Reading List links, parse the URLs out of them, and then you can send the links to the Instapaper Simple API to store in your Instapaper account.
I've got some extra jazz in there that keeps track of the last time it ran, only grabs links newer than that, and after submitting, throws up a little Growl message that lets me know the link was submitted successfully.
It's about 83 lines of code (and I'm a pretty crappy ruby programmer) and, so far, it works pretty flawlessly.
But, what good is that if I have to run a script every time I want to sync up my Reading List and Instapaper? Wouldn't it be awesome if there was a way to automatically run the script whenever the Reading List is updated?
It would be.
And there is.
launchd is a nifty cron-like thing that runs on the Mac. You tell it to do automatic stuff and it does it. One of the automatic things you can tell it to do is "watch this file, and if it changes, run this command."
After a bunch of trial and error, I got my little LaunchAgent working, and now, every time I add something to the Reading List in Safari, I wait about 10 seconds, and I get my little Growl notification that the link has been submitted to Instapaper.
Awesome, right?
Even better, now I can add things to my Reading List on Safari on my iPad or iPhone. When my computer next syncs up its bookmarks, it'll submit those links to Instapaper.
Even better than that, if I put the little touch file (that keeps track of when I last updated) onto something like Dropbox, I can run this utility on any computer I want, adding links to the Reading List all the while, and things should appropriately get added to Instapaper.
All in all, it's a nifty little system.
I'm going to throw the whole thing up on Github at some point this week, so you can download it and play with it yourself (and probably make it better).