AppleScript: Setting "search results" doesn't work as expected

Setting search results used to preserve the order of the record list passed to it, I think. However now it doesn’t do that anymore. After a macOS restart it seemed to be fixed but unfortunately this was only temporarily.

-- Test - Set search results to selection

tell application id "DNtp"
		if exists think window 1 then
			set theRoot to root of think window 1
			set theRecords to selected records
			if theRecords = {} then error "No selection"
			error "No window"
		end if
		set theRecord_Names to {}
		repeat with thisRecord in theRecords
			set end of theRecord_Names to name of thisRecord
		end repeat
		set newWindow to open window for record theRoot with force
		set search results of newWindow to theRecords
		return theRecord_Names
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

I noticed on your screenshot that the results have a relevance but shouldn’t. This is probably the relict of former searches and affecting the script (and therefore restarting the app fixes this at least initially). I’ll fix this.

1 Like