Action to perform DevonAgent search?

Before I try to do this, has anyone created an action to initiate a DevonAgent search?

(I also have this as an open question in the DEVON forums.)

The first thing to note is that DEVONagent has three different versions Lite, Express, and Pro, and you may find that some potential solutions can vary a little between them.

If you have not looked at them already, the standard (text) services might give you the functionality you are looking for across all applications, and not just Drafts.

2023-10-08-13.13.47

You can enable them via Preferences > Keyboard > Keyboard Shortcuts … > Services > Text, and you can also specify a keyboard shortcut.

This will populate the DEVONagent search field with the text to search for, but it does not trigger the search - you have to press return to do that.

DEVONagent supports AppleScript, and so it seems like it should be relatively easy to get Drafts (or you could build a service of your own) to run some AppleScript to do the same. However, triggering key presses through AppleScript automation triggered from other apps seems to be a bit of a known limitation in terms of permissions and Apple generally not liking scripts sending keypresses behind the scenes.

I gave working something up a shot this afternoon and could not get anywhere with adding the right accessibility permissions in. The error complains of osascript permissions, but combinations of giving that permissions, and Drafts, and Terminal, and DEVONagent, and reboots yielded no change in behaviour. In the end I approached it in a slightly different way, and one that probably gives better flexibility, but for you it may be a two step rather than one step download and install.

The approach is based on the fact that Shortcuts can easily be given access to send keypresses with AppleScript via adding permissions for siriactionsd (‘Siri actions daemon’ I think). You should get prompted to give it access first time you try and get Shortcuts to do this. But you can add it manually too, and enable its access.

Here is the AppleScript-based shortcut I created to trigger the search including the return key press.

https://www.icloud.com/shortcuts/9a4e1b5b3e6848b391fea7ca1ffba605

If you select text in an app, then right/control-click, you will see “DEVONagent Search” as an option in the Services sub-menu. You can also assign the Apple Shortcuts shortcut a keyboard shortcut (why did Apple take “Workflow” and choose “Shortcuts” an equally confusing term when you try and talk about it?) for quick access.

As another option, that comes back to your original request, you can then also use a Drafts action to call this shortcut with the current selection in Drafts (or the whole draft content if no text selected) if that’s a particular preference for you. Here’s a one step Drafts action that does just that using the shortcut above.

Of course even with the Drafts action to trigger it will still work in other apps too as this is an additive trigger option. It is using centralised logic so if you update the shortcut in any way, Drafts will also be calling that central copy with your update along with anywhere else you might use it.

Hope that helps.

1 Like

Thanks so much for the thorough answer!

Yes, I did mean DEVONAgent Pro, as you reasoned.

I would like to include the search set, so what’s the best way to do that? Separate Applescripts for each set, or a parameter passed in?

The syntax is

		search <string1> of input using set <string2> without minimized window 

The sets are nested - so I need to figure out that as well…

Thanks again!

“Best” longer term would be a parameter as it provides you with a single script, so any maintenance (e.g. a new parameter to add for a new feature) can be applied in one place and be used by all instances.

“Best” short term might be to do separate scripts if you want to use straight away, are unsure of how to parameterise and don’t have capacity right now to figure it out), and your variations are low (e.g. 2-3).

“Best” needs some requirements or constraints to make it meaningful, so based on the above and whatever other insights you might have for your own needs, what does “Best” look like? Chances are it will be the first option, but it isn’t guaranteed.

That’s what I thought.

What is the best way to handle the parameter passing, using Drafts?

I can imagine using tags, then branch/case logic in the AppleScript, or is there another better way?

The action utilises a shortcut to which it is passing a parameter. I would imagine one action for each search set, and it would pass a static value to the shortcut alongside the text - the two presumably being passed as a single parameter that Shortcuts would then have to split.

In terms of the parameter, you could use a separator, configure as JSON to be processed as a dictionary, set the clipboard (easy but poor option if you might have something important on your clipboard), etc.

In the embedded AppleScript I would simply parameterise to accept the name of the set directly and handle any logic outside of that - e.g. pass the set name directly through from the Drafts action as described above.

For anyone who wants to check out the discussion on that forum:

1 Like