Automatically generating DT annotation document from PDF annotations

@chrillek,
Thank you for your response. It was your guide that led me to this point. Your opening statements on DEVONthink in your JXA guide led me to the forEach loop. I did look at the AppleScript from @BLUEFROG, but was not able to deduce how it treated an Array. I tried to reference Array notation to no avail. Thank you for bridging the gap in my understanding. When looking at the dictionary, which I did, how do you know the difference between a named parameter and one that can be passed as an argument to the function/method?

Dawob

E.g. have a look at this command:

The URL is a direct & unnamed parameter, all the others are named and optional. A required parameter looks like this…

name: Type : Description

…and optional ones like this:

[name: Type] : Description

1 Like

I feel your pain. The dictionary format is very old (very), and it has probably been developed with AppleScript in mind. Which has some weird (in my opinion) ideas about parameter passing with named and unnamed (positional) parameters which can be required or optional, too. So, the dictionary requires some getting used to if you are using JavaScript. As @cgrunenberg pointed out, there might be

  • an unnamed parameter, which is always the first one
  • an object of named parameters, some of which might be required
  • optional parameters are always written in brackets

Parameter types mostly translate directly from AppleScript to JavaScript. There’s a slight difference in AS between Text and String, afaik, but in JS both are simply strings. An AppleScript record is an object in JavaScript, and an AS list is a JS Array. AS dates are internally mapped to JS Dates and vice versa.

Note that DT uses the term record for its own objects, they are not to be confused with AS’s records!

@chrillek
I have used:

function performsmartrule(records) {
	const app = Application("DEVONthink 3");
	app.summarizeHighlightsOf({records: records,to: "markdown"})
}

Still, I did not get a document or documents with the summarized highlights. The tags update, but I get nothing else.

I’m not sure how summarizeHighlightsOf works and I do not use highlights myself. The method returns a record, so it might be worthwhile to do something like
const result=app.summarize...; console.log(result.name());
and then search for the name in DT.

Edit I had a look at @BLUEFROG’s script. It does in fact loop over all the records, so your original approach was closer to the original version. So, another version would look like this

function performsmartrule(records) {
  const app = Application("DEVONthink 3");
  records.forEach( r => {
    app.summarizeHighlightsOf({records: [r],to: "markdown", in: r.locationGroup()})
  })
}

That is a verbatim translation of the AppleScript code (as far as I can see, that is) and it should produce the summarized highlights for every record in its location group.

@chrillek,
Thanks for the help, but there must be something wrong with implementing Javascript and Devonthink. It will not make individual summary documents. There are no errors, and it does apply the summarized tags. The script is running but not actually creating the summary files. The Applescript works fine, so I am using that for now. I would like to change to Javascript at some point, but I’ve spent enough time on this little project. Thank you, and I look forward to the future growth of JXA.

@BLUEFROG, how do you direct the summaries into a specific group of a database with Applescript? I cannot seem to find the syntax for making that happen. Thanks in advance.

Hi @dawob, it looks like we’re trying to do something similar and I’ve opened a related thread at Script Summarize Highlights from Javascript

We may have identified a bug in JXA but not sure yet