Help with coding to open a window

I am trying to write a script which includes opening a document or group in a new window (equivalent to double-clicking a selection.) I cannot find the syntax to open a new window from a selection however. I have tried the following code:

tell application “DEVONthink Pro”
activate
set theSelection to selection
open viewer window of theSelection
end tell

This generates the following AppleScript error:
“Can’t get viewer window of {record id 10438 of database 1 of application “DEVONthink Pro”}.”

I would also like to set the view-style once opened.

Can anybody help? Thanks.

This script will open a window for each selected record (as does command-O). To set the view style of group windows you will need to use GUI scripting. Make sure you have GUI scripting enabled by selecting “Enable access for assistive devices” in the Universal Access preference pane.

tell application "DEVONthink Pro"
	activate
	set selectedItems to the selection
	repeat with z from 1 to count selectedItems
		open window for record (item z of selectedItems)
		if type of (item z of selectedItems) is group then
			tell application "System Events"
				if UI elements enabled then
					keystroke "2" using {command down, option down}
					delay 1 -- optional, may depend on the mood of your computer :-)
				end if
			end tell
		end if
	end repeat
end tell

Rudi,

Thanks. That works great. How do I code if I want to open a window of a record by the name of the record and not by selection? I am still having problems with the syntax for specifying a specific record to take an action on.

Some examples (you must fill in the correct names of the records you want to open):

tell application "DEVONthink Pro"
	-- record at root level
	open window for record (record "recordName" of database 1)
	-- record of a group located at root level
	open window for record (child "recordName" of parent "groupName" of database 1)
	-- record located two levels deep
	open window for record (child "recordName" of child "groupName(2. level)" of parent "groupName(1. level)" of database 1)
end tell

Rudi,

Thanks again. Just what I was looking for.

Ahh… so the trick is to use GUI scripting, which I’m surprised is necessary considering how scriptable DT Pro is. Thanks for that tip and the sample script!

Just a note because it took me awhile to figure out and someone else might want it later:

To open a viewer window at the top level use this:

[color=darkblue]open window for record (root of database 1)

You need this if you activate DTP and all windows have been previously closed.