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:


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:


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: `${} (Annotation)`},
		 {in: annotationGroup});
            /* Add the template data and the content of the Notes to this new record */
	annotation.plainText = `**Document**

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


      /* 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.