JXA: getRecordWithUuid returns null in DT4 beta

(() => {
  const app = Application("DEVONthink");
  console.log(app.selectedRecords[0].uuid());
  const rec = app.getRecordWithUuid('6E8B33C2-65FF-4FA8-916B-D1AABA0B8F10F');
})()

gives me this in Script Editor:

app = Application("DEVONthink")
	app.selectedRecords.at(0).uuid()
		--> "6E8B33C2-65FF-4FA8-916B-D1AABA0B8F10"

/* 6E8B33C2-65FF-4FA8-916B-D1AABA0B8F10 */
app = Application("DEVONthink")
	app.getRecordWithUuid("6E8B33C2-65FF-4FA8-916B-D1AABA0B8F10F")
		--> null

using getRecordWithUuid with a “x-DEVONthink-item://” prepended to the UUID doesn’t change anything.

The equivalent AppleScript works just fine

tell application id "DNtp"
	set r to get record with uuid "6E8B33C2-65FF-4FA8-916B-D1AABA0B8F10"
end tell

gives

tell application "DEVONthink"
	get record with uuid "6E8B33C2-65FF-4FA8-916B-D1AABA0B8F10"
		--> content id 17942 of database id 2
end tell
Ergebnis:
content id 17942 of database id 2 of application "DEVONthink"

Am I doing something stupid?

That is interesting. As you well know, my scripting abilities are way below yours :smile: but I’ve just now been messing around with some AppleScript—really basic stuff combined with an Alfred workflow to clear DEVONthink search bar and highlight again (in the sidebar) a group I wish highlighted. The script is based on a script on page 260 of the manual:

-- Set the database we want to use
property pDatabase : "/Users/stapp/Documents/DEVONthink/Diaries.dtBase2"

tell application id "DNtp"
	set theDatabase to open database pDatabase
	-- Set the current year group in the Diaries database
	set currentYearGroup to get record with uuid "316F4FF6-59CC-4EFE-9B3F-2AAB64FC0BE2"
	set theRecord to currentYearGroup
	set root of main window 1 to theRecord
end tell

Sometimes that script works and sometimes it goes to a Temp folder in the database—which is not what I want.

No error message is shown in Script Editor and all I’ve discovered so far is that the error appears to happen depending on where I am within my group folders when the script is run. (E.g., /Diary entries/2000-2009/2008 may work fine, but for some reason if the script is run on /Diary entries/2010-2019/2014 it will not work properly.

Until I read your post I was going to keep quiet but have chimed in just in case it’s helpful.

Stephen

Can you clarify what that means? Does get record with UUID return the temp folder?

Sorry to have been unclear. The UUID is correct for the group I want. The Temp group has a completely different UUID. A simple get record with UUID picks the correct group but, it seems, depending on the year group I have highlighted in the navigation bar when I run the script (which is part of a workflow that first highlights and clears the DT search bar), the get record with UUID in the script sometimes, but not always, goes to the incorrect group. In case it’s relevant, the Temp group is a group directly off the database root and appears at the bottom of the list of groups in the database.

Stephen

Interesting. I still don’t get how get record with UUID can “go” to the wrong group. But I fiddled around a bit with my running DT: switches to another database and back to the one where the call failed – and now it’s working.

I do think that there’s some problem somewhere in DT, as this command should be completely independent of the currently selected database/group/record. @cgrunenberg might know more.

2 Likes

The UUIDs in your code example are not identical.

I am curious why you’re using theRecord instead of just using currentYearGroup.

<Sigh>. Oh dear, mere slavish, unthinking following the example in the manual. Thanks for the prompt.

However, even when changed to:

-- Set the database we want to use
property pDatabase : "/Users/stapp/Documents/DEVONthink/Diaries.dtBase2"

tell application id "DNtp"
	set theDatabase to open database pDatabase
	-- Set the current year group in the Diaries database
	set currentYearGroup to get record with uuid "316F4FF6-59CC-4EFE-9B3F-2AAB64FC0BE2"
	set root of main window 1 to currentYearGroup
end tell

the script still misbehaves on occasion as previously indicated.

Stephen

But nearly :wink: No idea how/why I missed the trailing “F”. Thanks for pointing it out!

Disable the command for setting the root of the window. When you run the script, what is returned in Script Editor?

In that case, this is invariably the (correct) result—whichever group I highlight in the navigation bar:

tell application "DEVONthink"
	open database "/Users/stapp/Documents/DEVONthink/Diaries.dtBase2"
		--> database id 2
	get record with uuid "316F4FF6-59CC-4EFE-9B3F-2AAB64FC0BE2"
		--> parent id 218234 of database id 2
end tell
Result:
parent id 218234 of database id 2 of application "DEVONthink"

Stephen

  • Is the Diaries database open when you run the script?
  • Is the Temp group always the one that’s erroneously selected?

Yes.

Yes.

Hmm…
Do you see the errant behavior with your code snippet, i.e., running outside your longer script?

Sorry, I didn’t really understand the question. :blush:

(I’ve run the whole script—as originally included in this thread—from the Script Editor (i.e., outside the basic Alfred workflow—which itself contains nothing more than keypress dispatches and pauses) and have the same problem as running it from within the workflow.)

No worries.
You said…

(which is part of a workflow that first highlights and clears the DT search bar),

So I’m asking if the excised snippet you posted here sometimes selects the wrong group or only when run within your workflow.

Both—i.e., whether run within the workflow or run from Script Editor. Just in case it’s any help the basic group structure of the database looks like this:

And you’re always selecting the group in the Navigate sidebar, not the item list, correct?

Correct. Sorry this is so tiresome when you have so much else on your plate. Please don’t treat it with any degree of urgency. It works much of the time…just not always!

Not tiresome at all. Just curious behavior indeed.