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');
recordArray.push(record);
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.
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
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?
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.
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.
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:
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:
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
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?