Search in all open databases with applescript

I am trying to write a little script to search in all open databases and return the results but noticed that the applescript search() method needs a in: parameter and searches only in the current database otherwise.

I wasn’t able to find a way to get a list of all currently opened databases either that I could use to loop through it.

Is it possible to use applescript to search in all of DEVONthink (similar to the search window, just programmatically)?

This will get you a list item of all open databases including the Global Inbox:

tell application id "DNtp"
	set allDatabases to every database
end tell

You can then do a loop with

repeat with thisDatabase in allDatabases…

For example, I have a Keyboard Maestro macro that, when executed while a file is selected in Finder, tells me if that file also exists inside some database. This is helpful if am cleaning up some downloaded files and don’t recall if I imported the file or not.

repeat with thisDatabase in allDatabases
		set t_fnd to (contents of thisDatabase whose name is i_fileName)
		set for_ to for_ & "In: " & name of thisDatabase & return
		set locList to ""
		if t_fnd is not equal to {} then
			repeat with thisItem in t_fnd
				set locList to locList & location of thisItem & name of thisItem & return & return
			end repeat
			set locList to "Nothing found" & return & return
		end if
		set for_ to for_ & locList
end repeat

(The snippet is an example of the technique. I won’t explain the whole macro as it is private to my work.)

Thanks, that helped a lot! Works great

Now I saw that each record has ‘score’ field. I assumed this would be the score of how good of a match the result is, but it looks like it’s always 0. Did you by chance figure out how to use it?

2.10.2 fixes the score = 0 bug. Make sure you’re updating your software.

Oh thanks! i’ll try that

NOTE: the script I posted here no longer works. Please do not use old scripts.