How to set the comment of a record via AppleScript

Borrowing a bit from the Add Selected Text to Comment script, I have the following AppleScript:

tell application id "DNtp"
	set filePath to "/Users/ericg/Desktop/document.pdf"
	set dp to import filePath to current group
	set theWindow to think window 1
	set dpUUID to uuid of dp
	set cp to (get record with uuid dpUUID)
	set comment of cp to "hello"
end tell

I do see the document appear in the DevonThink UI.

I am expecting the comment of the document I just imported to have its comment set to “hello”. Using Script Debugger, I can see the comment property being changed correctly.

However, in the DevonThink App, the comment is not updated.

What more needs to be done?

In your code, you have created record dp
Why not set comment of dp to “hello”
Why switch to record cp?

The simplified code works for me

Setting the think window is useless here. As are all the shenanigans with UUID etc, as @DTLow noted.

(() => {
  const app = Application("DEVONthink 3"); 
  const rec = app.import('/Users/ericg/Desktop/document.pdf');
  rec.comment = 'Hello';
})()

is all that’s needed (in JavaScript).

In general, if you find that your AppleScript or JavaScript code does not do what you want, you should run it in Script Editor, activating the protocol (Cmd-3). Then check the events and the answers tabs.

@DTLow

The reason for the switch was that the simplified code wasn’t working, so I tried something else which also doesn’t work.

Doing:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application id "DNtp"
	set filePath to "/Users/ericg/Desktop/document.pdf"
	set dp to import filePath to current group
	set comment of dp to "hello"
end tell

Does not work. The document shows up in the Application, but the comment property is not set.

@chrillek I suggest checking out Script Debugger. It is an improved experience over Apple’s Script Editor, providing additional tools for debugging.

Regardless, I ran the same script with Script Editor and this was the result:

Still not working. Comment not applied to the document in the application.

You are looking in the wrong place. You should be looking at the Annotations & Reminders > Finder Comments inspector.

Well, that is unexpected.

Is it possible to set the comment property via AppleScript? i.e. the field that shows up here:

image

No, those are not properties to use in whatever way you see fit for whatever file types you want to work on.

The Finder Comment is the recommendation in this case as its format-agnostic.

I fell into the same rabbit hole, happy to find the answer here.
So the property “comment” will change the “finder comment”, not the “comment”.
What is the “comment” which is not the “finder comment” for?

What is the “comment” which is not the “finder comment” for?

It’s a different type of metadata used on certain file types, e.g., rich text.
Finder Comments can be used on any file type.

And Finder comments are limited to Apple’s file system – they will not survive if the file is sent to Windows or Linux.

1 Like

Indeed that is true. Platform and filetype-agnostic metadata is still a weak point on any OS.