How to open a group in new window in a new space?

Yes, it’s generally quite annoying and it’s very annoying if due to this a script acts on the wrong window:

That’s what I do too. Finally made a handler after reading this thread.

-- Open a new window

tell application id "DNtp"
	try
		set newWindow to my openNewWindow("DB278225-DEF3-40D7-9F38-A5A28961CBEA") -- set UUID of the group you want to open a new window for
		activate
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
		return
	end try
end tell

on openNewWindow(theGroupUUID)
	tell application id "DNtp"
		try
			set theWindowUUIDs to uuid of root of every think window
			set theGroup to (get record with uuid theGroupUUID)
			
			if theGroupUUID is not in theWindowUUIDs then
				set newWindow to open window for record theGroup
				return newWindow
			else
				set theParentUUIDs to uuid of parents of database of theGroup
				repeat with thisParentUUID in theParentUUIDs
					if thisParentUUID is not in theWindowUUIDs then
						set newWindow to open window for record (get record with uuid thisParentUUID)
						set root of newWindow to theGroup
						return newWindow
					end if
				end repeat
				set newWindow to open window for record (get record with uuid thisParentUUID) -- Fallback
				return newWindow
			end if
			
		on error error_message number error_number
			activate
			display alert "Error: Handler \"openNewWindow\"" message error_message as warning
			error number -128
		end try
	end tell
end openNewWindow
1 Like