AppleScript: Refresh display after search

I use the AppleScript command

set search query of viewer window 1 to "xxxx"

to search in DTP3 from a database application.

This usually returns one result.

Unfortunately the document displayed in the DTP3 viewer does not change unless I click on the line in the search result list.

I’ve added

set selection of viewer window 1 to first item

which selects the first line in the results list but the document display still does not refresh.

How can I get the display to refresh with AppleScript or do I need some kind of GUI scripting?

Could you please post the complete script? Thanks.

I’m searching for an ID number in the custom metadata field named mf
I’d like to see the matching document in the DTP3 viewer without additional GUI actions.

Here is the AppleScript:

on run argv
    set mfRef to item 1 of argv
    tell application id "DNtp"
	    set search query of viewer window 1 to "mdmf:=" & mfRef
	    set selection of viewer window 1 to first item
    end tell
end run

Everything works except I have to click on the line in the search result window to get the document in the viewer to refresh.

This should theoretically work:

tell application id "DNtp"
	set theWindow to viewer window 1
	set search query of theWindow to "Test"
	set theResults to search results of theWindow
	if (count of theResults) is greater than 0 then set selection of theWindow to {first item of theResults}
end tell

However, this is not yet supported but will be by the next maintenance release.

Thanks.

Currrently the line

    if (count of theResults) is greater than 0 then set selection of theWindow to {first item of theResults}

reverts the results list to whatever was displayed before the search.

I’ll wait for the next maintenance release.

Actually, with…

	set res to (search results of think window 1 as list)
	set selection of think window 1 to {item 1 of res}

the item is indeed displayed in the view/edit pane, but the search results are closed. This is easily shown by checking the items in the search and specifying item n of res.

And the next maintenance release won’t close the search anymore if the desired selection is part of the search results.