Safari's Reading List to Devonthink

[size=85]–Rewritten, Jan 7, 2015[/size]

ReadingList2Devonthink

These lines of code aim at providing a tool to transfer articles stored/bookmarked in Safari’s Reading List to a Devonthink database without loosing metadata like when the document was saved in the Safari reading list and the original URL. The documents that end up in Devonthink are usually nicely formatted as the script uses the Instapaper paper service.

The solution consists of a python script that gets necessary data out of Safari’s bookmark.plist; an applescript that steers the actual importing of articles into Devonthink; and a Keyboard Maestro macro to clean up the just imported records in DT. The result should be akin to the following:

Usage

  • Put all script files in one folder, e.g., /Users/Myname/Desktop/RL2D/
  • Open the Terminal, type “cd /Users/myname/Desktop/RL2D/”
  • Run the Python script by typing “python readinglisturls.py” in the Terminal window. It should result in a file called readinglistdb.txt in the same folder. In case an error occurs: I might possibly have forgetten something here. I vaguely recall Python requiring the installation of another module or script or library.
  • Open the applescript ReadingList2Devonthink.scpt in the Script Editor app. Adjust the variables in the user setting section at the top of the script. The variables loop_min and loop_max define the first and last reading list item of the bookmarks.plist that are to be imported into Devonthink. Use, say, 1 and 10 to test the script.
  • Run the applescript ReadingList2Devonthink.scpt. It eventually lets Devonthink import these files or download them from the web using Instapper’s services. The records are created in the Inbox of the currently selected database.
  • Run, if possible, the Keyboard Maestro Makros. The import procedures leaves some annoying lines of text at the top of each document, the macros deletes those lines. Localise those two ‘Press Button’ segements; on an English machine, “Weiter” would probably be “Continue” and “Ersetzen” “Replace”. Select the first record in DT that should be processed. Run the macro; it will ask you how many documents below the current document should be processed.

Note to fellow script coders

I would certainly prefer a single script, and I think its possible to have all the code for this solution in one applescript.
As I haven’t been too familiar with handling XML (the bookmarks.plist file basically is an XML file) in applescript previously, I’ve just reused and modified some existing python code available on the nets to parse the bookmarks.plist.
Alas, I haven’t found a way to code against Devonthink in Python, so I wrote that applescript to manage the actual importing process.
The Keyboard Maestro Macro is an easy hack to remove some unnessary text introduced by the Instapaper service at the top (“Instapaper” “Save to Instapaper” “Move” “Share” etc.) and bottom of imported records. Again, it would be possible to replace these KM Macros with some applescript/PERL/regex code that manipulates the HTML code of the formatted note in Devonthink.
If you happen to have ideas, time, code for improvement, feel free to alter the code in any way you want.
RL2D.zip (259 KB)

Andreas, this is a great contribution – thank you for all the time and effort.

I believe most readers will not understand the steps they need to take to implement your solution on their own computers. Could you include step-by-step instructions? Most readers will not be familiar with installing and running Python scripts. There are file locations coded into the scripts. Also, it is not clear how the KM macro “clean(s) up the just imported records”. (It is possible to export KM macros, zip them, and post as attachments. That would ease the implementation.)

I know these are extra steps, but could help readers use this very important contribution. Thank you for all the effort.

Brett Terpstra (tech blogger) posted an alternate approach to extracting the Safari reading list (to Pinboard or Markdown) --> here.

I have rewritten my original post following korm’s suggestions.

An automated way to get Reading List items into DT would be great indeed. However, it would presumably require to have a unified script in either Python or Applescript. Maybe some other coders in this forum want to chime in or contribute some code. I have added some remarks on that in the first post.

A really cool script!

Do you think it would be possible to wrap it into an AppleScript package? That would make it possible to add it to DEVONthink Pro’s Script menu and distribute it via the Support Assistant.

As far as I recall, the sprachregelung in this forum in such cases is akin to: No news right now but we’ll try to improve this in future releases. :wink:

Here’s a version that puts it all together into one applescript file. I have’t thoroughly tested the script, but here on my computer, it works nicely. The script still is not entirely autonomous as it requires the installation of a scripting addition to perform the regxes.
ReadingList2Devonthink.applescript.zip (6.95 KB)

1 Like

I couldn’t figure out which Regex pattern to use in a shell script command called from Applescript.

PATTERN 1
–Pattern 1 aims at removing 23 lines of Instapaper menue clutter; a dozens of lines inbetween tags
–Following search patterns work:
–in regexr.com: <\snav[^>]>((.|\n|\r))<\s/\snav> --needs to be replaced by empty string, nothing, etc.
–in RegExRX app: <\s
nav[^>]>(.?)
–in TextWrangler (PCRE), Perl, Python, sed: no idea

Ideas anyone which search pattern and shell script command would do the trick without Satimage’s scripting addition?

Hello,
even though this thread was a little while ago, such a thing would be exactly the solution I needed! Unfortunately the download seems to be broken?
Is there still “the project” or another solution?

Many greetings AlexD

Is there a specific reason you want to store a reading list in Safari first and not only use DT or DTTG?

When I am on the road or at home spontaneously or due to a special search in the net, I can very quickly and easily create a reading list, which I can view and / or work through at both places at any time. I don’t know how to save a website from Safari in DT3 directly into the reading list. I only know the cumbersome way of saving a website as a bookmark and including the bookmark in the booklist via the context menu. But since I often decide only when I read it calmly whether the post is worth keeping it, in many cases I would have to delete it from the booklist first and then from the database.

Also, there is no comparison to DEVONthink GO. I hope I have written the problem understandably.

Many greetings!

I’m not entirely sure what you mean, or if it fits your needs, but simply dragging the Safari URL to DT or the sorter creates a bookmark to that website.

Would that work for you?