After Creating a Document in A Group How can I have that Document Selected

I am learning a little automation and here is my code to create a new document.

set boilerplateTemplate to "~/Library/Application Support/DEVONthink 3/Templates.noindex/My Templates/%title%.md"

tell application id "DNtp"
	set docTitle to (text returned of (display dialog "Enter the title:" default answer "My Note"))
	
	set newRecord to import boilerplateTemplate placeholders {|%title%|:docTitle} to current group
	set comment of newRecord to ("Hello World") as string
	set newRecordPath to (path of newRecord)
end tell

After that record is created I want to have it selected so I could begin writing.How can I do this.

Help would be appreciated.

Thanks

Nice!

Did you check the AppleScript dictionary?
Look for selection. What do you see there? (Hint: Look at the one for the viewer window.)

Hi @BLUEFROG

I think you mean

set selection of theviewer window to ????

I am just not sure what to set it to?

I got it, Thanks for your help.

tell application id "DNtp"
	set this_window to viewer window 1
	set docTitle to (text returned of (display dialog "Enter the title:" default answer "My Note"))
	
	set newRecord to import boilerplateTemplate placeholders {|%title%|:docTitle} to current group
	set comment of newRecord to ("Hello World") as string
	set newRecordPath to (path of newRecord)
	set selection of this_window to (newRecord) as list
end tell

@DTLow, @BLUEFROG
Thanks for your help.

You’re welcome!
And indeed, I wanted you to see a selection in a viewer window is a list!

Noting how you approached it wasn’t wrong, here’s a little briefer version without setting a variable for the window or coercing the record as list

set selection of viewer window 1 to {newRecord}

PS: In case you didn’t know, window 1 - whether viewer, think, or document windows - is the frontmost window.

PPS:
viewer window is a main window, i.e., the one with the sidebars, search pane, etc.
document window is a window with only a document you’ve opened, e.g., after double-clicking a file.
think window is an umbrella element encompassing both types of windows.

Thanks, now I know the curly brackets denotes a list

Really very helpful.

Much appreciation to you, @BLUEFROG , for sharing your knowledge.

Thanks

Steven

You’re very welcome. :slight_smile: