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.


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


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:


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.