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.
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
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.