Script to create a location-specific search link

I’ve hacked/written a script to create and save a link to a DT search:

display dialog "Search text" default answer "" buttons {"Cancel", "OK"} default button 2
set theAnswer to the text returned of the result
set theURL to "x-devonthink://search?query=" & theAnswer & "&open=1”
tell application "DEVONthink 3"
	create record with {name:theAnswer, type:bookmark, URL:theURL} in current group
end tell

However, this searches all databases. Is there a way to modify the URL to search within a specific database or group?

1 Like

You could use a scope, e.g. to target a database but not the specific group,…

x-devonthink://search?query=test%20scope:File%20Types&open=1

Thanks! That works!

1 Like

You’re welcome :slight_smile:

Thanks for sharing, @acoyne.

The ability to link to search results is quite useful to quickly access parts of the database that are being replaced dynamically via a script, such that the item links change.

For example, I use a workflow to automatically transclude various individual markdown notes (which change frequently) into summary documents. These are regularly replaced by new versions.

Using the URL generated by this script (and/or making manual modifications), it’s possible to reveal these kinds of documents even if the item link changes. It’s also possible to use a script (and hotkeys) to reveal these items based on the search link.