Script Summarize Highlights from Javascript

Hi there,

I’m trying to script the summarize highlights functionality that looks like it was added in 3.7 based on another forum post.

Unfortunately I can’t get it to work at all. For example, putting this in Script Editor:

var app = Application('Devonthink 3');
app.includeStandardAdditions = true;
let recordArray = [];

var record = app.getRecordWithUuid('8ACF855F-7991-4B96-B90B-DF80ADFB7F47');
let summary = app.summarizeHighlightsOf({records: recordArray, to: 'markdown'});

Results in summary always being null, despite the fact that I can run Tools > Summarize Highlights and it will generate a summary file. I’m still figuring out the intricacies of the javascript API and learning to adapt AppleScript examples to JS, so I’ve tried formatting the parameters in various ways to no avail.

Is anyone able to do this successfully?

This is the 2nd similar report concerning the JXA version of this method. I suppose that there’s some glitch somewhere, @cgrunenberg would have to assess.
According to the scripting dictionary, your call looks ok.

I suggest that you use const whenever possible instead of let and var, though. That prevents involuntary modification of values and leaking of variables into the global scope (where they don’t belong).

Edit: Running the script in Script Editor shows these messages

app = Application("DEVONthink 3")
	app.summarizeHighlightsOf({records:[], to:"markdown"})

So, obviously, the records list passed onto DT’s guts is empty. Which it shouldn’t be.

The only other mention this month I can recall was actually due to an invalid script syntax but maybe you’re having something else in mind.

It started out with an illegal syntax. But later the OP corrected that and still didn’t get it to work:

That’s why I thought that we have two reports of the same problem now.

In case of smart rules the in parameter should be always specified otherwise the summaries might be created in unexpected locations. But the last version posted by you should actually work and create a summary for each record or did you experience any issues?

Edit at the end

The last thing I posted here was the output of Script Editor’s message pane. And that (seems to) show that DT gets passed an empty record array. If that is what’s happening here, there will be of course no new highlighting record be created.

I checked my Verlauf smart group for any new records in the last several days, and none of them was even remotely looking like a summary of highlights.

Edit I tried to write the same thing in AppleScript like so

tell application id "DNtp"
	set r to get record with uuid "1626AE02-7B82-4404-8074-8683B71A69BE"
	set summary to summarize highlights of records {r} to "markdown"
	log name of summary
end tell

Running that in Script Editor shows me that summary is returned as missing value (consequently, log name of summary throws an error). Now I’m wondering if

  • I don’t understand the whole concept of highlighting. For the test, I selected words in a OCRd PDF and “highlighted” them in yellow. And I used this records’s UUID in the scripts (verified by logging the name).
  • or if I do something utterly wrong when calling the method
  • or if something just doesn’t work the way it should be

I referred to your last script in the other thread actually which should work as expected. But it doesn’t as DEVONthink doesn’t receive a valid records list. Oh well… the joys of the automatic JXA bridging.


Sorry for that. But the question still remains why my AS version doesn’t work either (although it does get passed the records list).

Syntax issue actually once again due to the subtle differences of JXA and AppleScript :slight_smile: This…

set summary to summarize highlights of records {r} to "markdown"

…should look like this:

set summary to summarize highlights of records {r} to markdown

So I can confirm that running the AppleScript version works for me

tell application id "DNtp"
	set r to get record with uuid "8ACF855F-7991-4B96-B90B-DF80ADFB7F47"
	set summary to summarize highlights of records {r} to markdown
	log name of summary
end tell

However, I’m not sure what the equivalent JXA would be - if you do markdown without quotes it would be an unreferenced variable…

The original JS that myself and @chrillek posted retrieves the record correctly, but it’s the call to summarizeHighlightsOf that just doesn’t do anything. The files aren’t created anywhere AFAICT.

According to the scripting dictionary, you have to enclose it in quotes. This is analogous to the type property of DT records: In AS, they’re something else than in JS, and in the latter you have to use quotes whereas in the former you mustn’t.

Unfortunately DEVONthink doesn’t receive a valid records list and therefore can’t do anything (or even work around this JXA issue).

What a mess. The same is happening with merge. OTOH, it seems to be no problem to return a list of records from DT in JavaScript.

Well, returning is handled by DEVONthink, receiving by macOS and all its layers & bridges.

Yeah, it’s true - I’ve been building out a small toolchain in JXA and so far none of the other operations have a problem:

  • find by id
  • create new record
  • delete record
  • create pdf from URL

I’m not sure if that helps, but I found that at least two apps do receive an array with the desired values.
The first is GraphicConverter

(() => {
  const app =Application("GraphicConverter 11");
  const w =;
  app.changeResolution(w[0], {to: [900,900]});

And the Events pane in Script Editor says

app.changeResolution(, {to:[900, 900]})

So, the to array is not empty.

And another example with Mail:

(() => {
  const app =Application("Mail");
  const box = app.accounts.byName('xxx').mailboxes[1]();
  app.performMailActionWithMessages([box.messages[0], box.messages[1]]); 

which gives me this in the Events pane:

app.performMailActionWithMessages([app.accounts.byId("496A6C64-F3D3-48ED-8527-CB39974E3BAF").mailboxes.byName("INBOX/Sent"), app.accounts.byId("496A6C64-F3D3-48ED-8527-CB39974E3BAF").mailboxes.byName("INBOX/Sent")])

Again, the list parameter is filled with the objects I want to populate it.

These two cases seem (!) to indicate that it might not be a general problem of the JXA scripting innards which prevents the records array to contain what it should contain.

Assuming this is a problem without a short-term solution, would you (or maybe @BLUEFROG) recommend an alternative workaround? Here’s what I’m trying to do:

  1. In an obsidian note corresponding to a URL, push a button called “sync devonthink”
    a. If the item doesn’t exist in devonthink, create a PDF record and link obsidian and devonthink (this part works)
    b. If the item exists, regenerate highlight summaries and copy the markdown back into obsidian and then delete the summary item (this part doesn’t work)

I’m invoking this from an obsidian plugin (hence javascript). But it looks like there are a couple of alternatives:

  1. A smart rule? Something that will auto-generate summaries when a PDF gets highlighted and updates the original record somehow to let me identify them
  2. Shortcuts and AppleScript - I can invoke shortcuts from obsidian and can trigger AppleScript from a shortcut.

I’m a total beginner at both smart rules and AppleScript - I think the sample AppleScript above is probably a decent starting point. Do any of you have a suggestion?