Search for custom meta data in AppleScript

How do I search for the contents of a custom meta data field in DEVONthink by Applescript? I managed to make it work for the text contents with this:

set searchResults to search theId within text contents

but would like to achieve something like

set searchResults to search theId within <my custom meta data field>

The within parameter is actually obsolete and unused since version 3. However, you could create the search term e.g. via the advanced interface of the toolbar search.

Thanks, but I need to do it with AppleScript. Background: I am integrating a FileMaker database into my DEVONthink workflow and want to achieve this:
I have a record with a unique ID in FileMaker and want to do something with the records in DEVONthink that have this FileMaker ID in a custom meta data field.

The search command supports the same syntax (including all prefixes & operators) as the toolbar search. Therefore a command like…

search "mdidentifier==" & theId

… should work, the actual identifier can be found in Preferences > Data.

And if this supposed to be done in an active DEVONthink window, you can use something like this…

tell application id "DNtp" 
set search query of think window 1 to "mdstatus==No Status scope:all"
end tell

this works great, thank you.

set search query of think window 1 to "mddbid:0012488 scope:\"Slip-Box\""

works fine, but how do I access the documents which were found by the query?

got it:

set search query of think window 1 to "mddbid:0012488 scope:\"Slip-Box\""
set searchResult to search results of think window 1

does it! Thanks for your help

You’re welcome!

However, note the first line isn’t necessary unless you’re wanting to actually display the search.
You can use a shorter form, e.g.,…

tell application id "DNtp"
	set searchResults to search "mdstatus==No Status scope:all"
     -->{content id 14542 of database id 2 of application "DEVONthink 3"}
end tell

yesss, that’s what I wanted. Thanks again for your great support.

My pleaseure! :relaxed: