I had a bug report from Pablo yesterday about my Applescript based kindle annotations and highlights parser.

It seemed to be erroring when it was attempting to parse a phrase into a number

error “Can’t make "ur Highlight Location 82 " into type number.” number -1700 from “ur Highlight Location 82 “ to number

to be exact.

I’ve only ever had my own My Clippings.txt file to use as a test file so it came as no great surprise that someone else’s caused a problem. Interestingly, to me at least, the format of the highlight and notes seems to have changed. On my kindle the format is

  • Highlight Loc. 218-19 Added on Friday, December 31, 2010, 10:36 AM

and sometimes like

  • Highlight on Page 12 Loc. 122-23 Added on Saturday, April 02, 2011, 03:30 PM

whilst on Pablo’s there are some like

  • Your Highlight on Page 103 Location 1505-1506 Added on Tuesday, May 21, 2013 2:57:09 PM

(note the use of Location rather than Loc. as in my version)

and some like

  • Your Highlight on Unnumbered Page Location 368-370 Added on Tuesday, April 2, 2013 10:08:27 PM

which completely threw me. Unnumbered Page. Helpful!

Anyway, I’ve updated the script to cope with both of these scenarios. I’ve tested it on Pablo’s My Clippings file, and on mine. It is still slow (over an hour for my collection of snippets) and I think leaks memory all over the place, but as long as it continues to work, I’m not going to be spending too much time refactoring it - applescript is not something I tend to play in. If I did refactor it, I’d probably move it into ruby or something with more parsing capabilities in-built.

The usual disclaimer applies: your mileage may vary, this is just something I wrote for myself. If it helps you, excellent news, and I’m happy to spend a bit of time, as in this case, to keep it working.