Request to set and trigger `search query` of document window programmatically

I want to be able to search within a document window, setting the search string programmatically (rather than typing or pasting into the Find field in the Inspector). It seems that this isn’t currently possible.

The use case is this: I save extracts from a pdf as separate plain text files. I include with each extract an x-devonthink-item link to the document/page so that I can easily jump back to view the extract in context. However, this works only at the page level. Further to this, I want to be able to write a script that will not only show the page but also immediately highlight the specific text that has been extracted—i.e. by searching the document for that string and moving the page to that position.

Viewer windows have the search query property that allows for the search string to be set. This also sets the search string for document windows. However, this involves a database-wide search, and it doesn’t allow for the search string to be actually triggered in the document window (it seems) unless the Inspector pane is open and the Find field is interacted with (in which case one might as well just paste into the field). I’ve got a Keyboard Maestro macro that will do this but it isn’t very elegant and causes some other problems.

Ideally, what would solve my problem would be this: for search query to be an editable property of document windows (independently from other DEVONthink windows), and for setting this property to highlight the first match in the document (like pressing ⌘G).

In Script Debugger, just to give an example, this can be done by setting the search string property and then using the command search with action find next.

1 Like

If I understand correctly what you’re trying to do, then this script created by @Bernardo_V and modified by yours truly should address your need.

After selecting a paragraph in the document, you trigger the script. The link including search query can then be pasted from the clipboard. Clicking this link opens the document and highlights the paragraph that was selected at the time the script was triggered.

On a cheeky side note, this thread is a great example of why we need a centralized collection of scripts :stuck_out_tongue: :innocent:

1 Like

Ah yes! That works perfectly. I remember seeing that thread but I hadn’t put two and two together. Thank you.

However, I can make a contribution in return: I have an AppleScript Objective-C script for URL encoding text. I’ll post it in the other thread.

[Edit: here it is.]

1 Like