Annotations vs Annotations?

I would like to create a smart rule (or batch process) that 1) finds Notes in my custom metadata of PDFs and 2) moves each note to the Annotation field of the PDF, ideally using the default text template (with a backlink). Has anyone created or tried this? I am seeing something similar: https://discourse.devontechnologies.com/t/new-rtf-doc-from-selected-text-with-url-to-pdf/14512/1

Thanks!
Thanks!

While a smart rule should be able to find the notes, it’s not possible to automatically generate annotations. This would require a script.

As @cgrunenberg said: You’ll need to script that. I posted a script showing how to set annotations in PDFs via JavaScript here:

However,

Such a thing does not exist. Annotations are bound to pages in the PDF. You can, of course, decide to attach them all to the first page (or the last, or whatever), but the basic idea is that they refer to something in the PDF.

backlink to what?

Due to the description @zoepster seems to prefer the record’s annotation, see Annotations & Reminder inspector and its default text templates, not PDF annotations.

1 Like

The DT scripting dictionary knows an annotation which is a record. That probably indicates a DT record. So, I’d create a MD record (for example) from a template, copy the PDF’s Notes custom meta data field to that one, add the link to the PDF document to the MD text (or somewhere else?) and then set the annotation property of the PDF to this new MD document?

Exactly, that’s how it should work.

And would it be possible to access the annotation template (MD or plain text) somehow from the script? I didn’t really find anything in the scripting dictionary…

I came up with this JavaScript code that can be run from a smart rule.

function performsmartrule(records) {
  const app = Application("DEVONthink 3");
  const se = Application("System Events");
  /* Get the users full name from System Events */
  const userFullname = se.users[0].fullName();
  /* Loop over all records that are PDFs (filter rejects the others) */
  records.filter(r => r.type() === "PDF document").forEach(r => {
    /* get the annotation group for this record's database */
    const annotationGroup = r.database.annotationsGroup();
       /* Get the custom meta data "Notes". Only if it exists and is not empty, create the annotation */
	const notes = r.getCustomMetaData({for: "notes", from: r});
	if (notes && notes !== "") {
        /* Create a basic markdown record in the current record's annotation group */
    const annotation = app.createRecordWith({
	     type: "markdown",
	     name: `${r.name()} (Annotation)`},
		 {in: annotationGroup});
            /* Add the template data and the content of the Notes to this new record */
	annotation.plainText = `**Document**
[${r.name()}](x-devonthink-item:${r.uuid()})

**Date & Time**
${(new Date()).toLocaleString()}

**Annotator**
${userFullname}  

**Notes**
${notes}
`;
      /* Set the new record as annotation to the PDF */
       r.annotation = annotation;
    }
  })
}

Since I don’t know of a way to access the MD template for annotations directly, I (kind of) copied the text verbatim into the script. Kind of, because I’m running in a German locale, so the headings are different from what you probably want. But you can adjust the MD (and anything else, of course) to whatever you like.

No, that’s not possible.

Thank you! I do need the record annotation. I will read these responses very carefully and try them out. Many thanks for these pointers and the discussion. Apologies for any lack of clarity.

Backlink to the PDF.

I have read through all of this thread, though some of it is beyond my expertise level. My use case is that I’m looking to make notes on articles (a brief summary of the pertinent points of the article essentially). Where would I be best to input that text? I’m guessing in the “annotations” box of the “annotations & reminders” section of the inspector pane - though am happy to be corrected if there is a more suitable method. Thanks!

Yes, using an annotation file is a commonly used way to take such notes.

1 Like