UUID for Frontmost Open Record Window

I have an applescript that adds a new record and the opens the window in edit mode from Keyboard Maestro

However I would like to run another script on this open window from KM that adds tags pulled from the existing tags in DT.

I have all this code working, but I do not know how to find the UUID of the record in this open window to add the tag. Can anyone point me in the right direction please?

Many thanks

If you showed your code, it might be easier to see what you’re doing.

Try this:

tell application id "DNtp"
	set theWindow to window 1
	if class of theWindow as string is equal to "document window" then
		set theRecord to get record of theWindow
	else if class of theWindow as string is equal to "viewer window" then
		set theSelection to (get selection of theWindow)
		if theSelection ≠ {} then
			set theRecord to item 1 of theSelection
		end if
	end if
end tell

And this does the same:

tell application id "DNtp"
	if count of selected records is 1 then set theRecord to selected record 1
end
1 Like

Thanks @cgrunenberg and @mdbraber. Both of these give me a result of…

content id 842 of database id 6 of application "DEVONthink 3"

I was expecting a “BEC44852-0102-4658-94F1-1DD0E0BDA052” type UUID.

Can I add tags to a record with id 842 of database id 6 ? I was thinking I would need the full UUID?

If I can’t crack this @chrillek I will post the KM scripts I have been using

Just add the line return UUID of theRecord

1 Like

If you want the UUID use what @cgrunenberg said. The code I suggested indeed ignored your request for the UUID and return the record object instead. With the record object you can operate on the record immediately like such:

set tags of theRecord to {"A","B","C"}
2 Likes

Perfect! Thanks so much guys. This was the missing bit of the equation for me. Having such AS support means I can ditch Drafts and Bear.

I love Devonthink!

2 Likes

Sorry one final question.

How would I find the database name from theRecord here…

tell application id "DNtp"
	if count of selected records is 1 then set theRecord to selected record 1
end

Add this line

set theRecord_Database_Name to name of database of theRecord

1 Like

Your main point of reference for these questions is the scripting dictionary. You can open it by dragging the DT program on the Script Editor.

There you’ll find all kind of information like available properties, methods and elements.

2 Likes

@pete31 Thanks so much!
@chrillek Thanks for the heads up. Very useful. Which has led me to another problem I will ask on a different thread

1 Like