Opening DTPro Search window and populating results?


I’ve just begun experimenting with automating DEVONthink Pro. I’m having trouble interacting with the Search window (Tools > Search…) using JXA.

My goal is to create a function which will search a specific database for all documents matching a given string, then list the results in the Search window for previewing. If possible, I’d prefer to do this without using UI automation/accessibility scripting.

I’ve been able to use the method to get a list of records, and I can iterate over that list to open every record in a new tab within the main ViewerWindow. I see there’s a SearchWindow class defined in the script dictionary, but I can’t seem to make one appear. If a SearchWindow is already open, I can access it through Application.searchWindows, but setting the results property doesn’t work. (If there are search results in the SearchWindow, when I set results to a list returned from, the window results become empty instead.)

Is it possible to script DEVONthink Pro to list search results from across a database in a new window? If so, what is the best way to do that?

Thanks for any help.

You can’t open a new search window, except by UI scripting.

You could also use our service: DEVONthink: Lookup to initiate such a search.

Note: We don’t specifically support JXA. AppleScript, we do.

The Lookup service does do what I want, so I’ll look for a way to integrate it into my workflow. Thanks for the help!

In case this helps anyone, here’s a way to use JXA to invoke the DTP Lookup service, which searches DTP using the clipboard contents as the search terms:


svcName = $.NSString.alloc.initWithUTF8String('DEVONthink Pro: Lookup...')
$.NSPerformService(svcName, $.NSPasteboard.generalPasteboard)

You can use this code in Automator with the “Run JavaScript” action, and can modify the clipboard contents with the “Copy to Clipboard” action:

[attachment=0]Screen Shot 2019-03-10 at 11.02.42 AM.png[/attachment]

1 Like

Thanks for sharing your snippet. Cheers!