Search a particular database via Alfred

Hi all,

I usually get by editing people’s applescripts, but have no real understanding on my own. I’d like to use Alfred to search a particular DevonTHINK database, but haven’t found any examples to customize. The existing workflow doesn’t seem to work in Alfred 3 and doesn’t seem maintained any longer. https://www.alfredforum.com/topic/2265-devonthink-document-search-updated-to-version-13/?tab=comments#comment-12749

Anyway, here’s what I’ve got. It doesn’t work, but maybe you can offer some pointers? What I’d like to do is have the workflow open DevonThink, select the specified database, and search it with the search query. I don’t need to open the special search window (although it might be neat to see how to do that). If you could point me to existing scripts, I’m happy to tinker with them as well.

on run
	set theQuery to "{query}"
	tell application id "DNtp"
		set theDatabase to open database "~/Documents/Notes.dtBase2"
		search theQuery in theDatabase
	end tell
end run
1 Like

Have you considered learning how to do this yourself? It’s worth the effort.

At some point I will be able to devote the time and resources to learning AppleScript and /or Javascript Mac automation, but other projects are a priority now, thus my request for help.

If there are a few AppleScript techniques / concepts that would help me accomplish my task, I’d appreciate being pointed in the right direction.

In your AppleScript editor (e.g., Script Editor or Script Debugger) you might want to confirm command syntax by browsing the DEVONthink scripting dictionary.

For example


search theQuery in theDatabase

is not correct syntax – and the script will fail silently. This is correct:


set theResult to search theQuery in theDatabase

The problem with this is that the commands do not cause the DEVONthink interface to open and display anything. They merely put data into a variable, and you need to do something with the variable. Have you script display it in a window, or something.

BTW – the Alfred workflow mentioned in the OP works fine over here in Alfred 3.4 [850]. There are several commands in the workflow, as discussed in the source. It is necessary to “prime” the workflow by declaring the database to search. Anyway – that’s off topic for this forum.

This turns out to be pretty easy with Keyboard Maestro:

https://forum.keyboardmaestro.com/t/devonthink-particular-database-search/7628