Readwise to Devonthink script

Hi,

My setup: Mac Studio M2 Max, Sequoia 15.3.1, DT3 3.9.8.

I’ve just come across this script, Readwise highlights to DEVONthink - BrettTerpstra.com on the DT3 forums, and it looks like it could be very useful, thanks!

Unfortunately I can’t get it to work – probably my fault. I have followed the steps in order, including:

  • updating the built in ruby to homebrew’s 3.4.1 (and made sure that my path reflects this
  • added my token to the main readwise script (not the additional config, nor as an optional arg on the CLI command).

I get the following error message the first time I run it:

95:185: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:183: execution error: DEVONthink 3 got an error: Invalid argument in (-50)

The readwise_last_update file is created properly, and the next time I run the command, there are no error messages.

However, there are also no files created in the Global Inbox (or anywhere else in DT3, either).

If I remove the last updated script and rerun the command, I get the same DT3 error as above.

When I ran the script for the very first time I was asked to give permission to DT3, which I did. Are there any other permissions I should give?

What should I try next, please?

Many thanks,

David

So sorry for the delayed reply here, I stopped getting notifications for a little bit there. I think I responded to this on the DT forum, but will repeat here.

I believe the issue is that I developed the script while using the v4 beta and didn’t realize that the update command wasn’t available on records in DT3. I removed that bit of code from the script, so if you grab the latest version, it should work. Please let me know if it doesn’t.

Thanks, Brett!

I’ll try it out and report back.

Best wishes,

David.

I found a major flaw with the script. I had commented out the offending lines, but when the highlight was injected it overflowed the comment lines and caused an AppleScript error every time. Fixed now.

Thanks, Brett!

I’m away at the moment, but will try it out as soon as I get back.

Best wishes,

David

@brookter any luck? It’s been working great for me, but I’m still working with the beta and haven’t tested on v3 at all.

Hi Brett,

Sorry about the delay.

Unfortunately, it’s still not working for me, on either of my two Macs (a MBP M1 Pro and an M2 Studio Max, both with MacOS 15.3.1 and DT3 3.9.8). The token is definitely right.

This is what I get:

$ readwise_to_devonthink.rb -d                                                                                    [13:50:20]
INFO: Last update record does not exist
INFO: 20 new highlights
INFO: Saved last update: 2025-02-28T13:50:30.662+0000
95:170: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:168: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
ERROR: Error getting annotation for Save Readwise Highlights to DEVONthink  GitHub
ERROR: Error undefined method 'empty?' for nil

Sorry, but this is way out of my comfort zone so I can’t offer any suggestions. I’m happy to try out anything you would like testing though.

Many thanks for doing this,

David

I think I can fix that. Will try to get a new version out shortly.

1 Like

Ok, try it now. I think the issue was here:

https://gist.github.com/ttscoff/0a14fcd621526f1ab2ac6fa027df0dea#file-readwise_to_devonthink-rb-L721

Updated the gist

Still getting an error, but it seems to be getting further: it’s now breaking on each import, rather than as a whole. I’ve omitted the repeating lines in the middle, but includex the final curl errors and no implicit conversion etc, at the end of the output.

Thanks again!

$ readwise_to_devonthink.rb -d                                                                                                                                                                                                                    [15:31:42]
INFO: Last update record does not exist
INFO: 20 new highlights
INFO: Saved last update: 2025-02-28T15:31:48.313+0000
95:170: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:168: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
ERROR: Error getting annotation for Save Readwise Highlights to DEVONthink  GitHub
161:236: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
⁉️ Error saving Save Readwise Highlights to DEVONthink  GitHub
ERROR: Error saving bookmark Save Readwise Highlights to DEVONthink  GitHub
95:148: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:146: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
ERROR: Error getting annotation for Emacs for Writing Prose
161:214: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
⁉️ Error saving Emacs for Writing Prose
ERROR: Error saving bookmark Emacs for Writing Prose
95:185: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:183: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
ERROR: Error getting annotation for Preventing a Mac Laptop From Turning on When Opening Its Lid
161:251: execution error: DEVONthink 3 got an error: Invalid argument in (-50)

(LINES OMITTED)

⁉️ Error saving Apple Intelligence Is Coming. Here's What It Means for Your iPhone
ERROR: Error saving bookmark Apple Intelligence Is Coming. Here's What It Means for Your iPhone
95:161: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:159: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
ERROR: Error getting annotation for Why Are We Still Eating So Much Meat?
161:227: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
⁉️ Error saving Why Are We Still Eating So Much Meat?
ERROR: Error saving bookmark Why Are We Still Eating So Much Meat?
95:140: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
curl: option : blank argument where content is expected
curl: try 'curl --help' or 'curl --manual' for more information
ERROR: Error no implicit conversion of nil into String

Looks like I’m going to have to dig my copy of DT3 back up to debug. I’m not getting any of these errors with 4. That last error on the curl call would be because something didn’t return a URL for a bookmark, which I thought I had fully handled, but apparently not.

Will look back into this over the weekend. It really is a useful script when it works…

1 Like

Thank you ever so much for doing this, Brett – I really appreciate it. (Just made a small donation as something a bit more tangible…)

Thank you.

I just installed DT3 and ran a test with 10 highlights and it worked perfectly.

Could you run the script with readwise_to_devonthink.rb -v and put the full output into a gist I could review?

(side note, I updated the gist with a slightly modified version that now captures quotes and html tags around highlighted Markdown sections better. Shouldn’t have any effect on the issues you’re seeing, though.)

Thanks!

Sorry, don’t know how to create a gist, so I’ve attached a text file: hope that’s ok. I created a new highlight, so the log is only picking one up, to make things simpler.

Hope that’s ok.

readwise_to_devonthink_log.txt (9.0 KB)

Ok, I think I got it. You clearly had your database/group set to “global” and “inbox” and I hadn’t fully tested with that configuration. It should now work like that, or you can specify a database and group and circumvent the issue entirely.

Grab the latest version of the script and it should function with your current settings.

Thanks, Brett.

This is the result with the standard script – i.e. with your default ‘global’ and ‘inbox’ settings.

$ readwise_to_devonthink.rb-copy -v                                                                               [14:57:09]
INFO: 1 new highlights
INFO: Saved last update: 2025-03-01T14:57:24.684+0000
95:129: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
93:127: execution error: DEVONthink 3 got an error: Invalid argument in (-50)
ERROR: Error getting annotation for Date

tell application id "DNtp"
        set theGroup to inbox

        set searchResults to search "name:\"Date\"" in theGroup
        if searchResults is not {} then
          set theRecord to item 1 of searchResults
          return plain text of (annotation of theRecord)
        end if
      end tell
ERROR: Error undefined method 'empty?' for nil

["/Users/david/bin/readwise_to_devonthink.rb-copy:735:in 'Import#save_to_dt'", "/Users/david/bin/readwise_to_devonthink.rb-copy:509:in 'block in Import#save_all'", "/Users/david/bin/readwise_to_devonthink.rb-copy:508:in 'Array#map'", "/Users/david/bin/readwise_to_devonthink.rb-copy:508:in 'Import#save_all'", "/Users/david/bin/readwise_to_devonthink.rb-copy:993:in '<main>'"]

If I change the name of the database/group to one of my other databases (‘Notes’ and ‘Inbox’), I get a longer response:

errorlog2.txt (13.8 KB)

Are you sure you updated the script to the latest version? Both of the errors I’m seeing in there were already fixed.

I thought I had… But I’ve just gone and downloaded it again and it’s working now!

I cannot thank you enough, both for the initial script and for your patience in tracking down the problems. I am very grateful!