Invoking Drafts Action via callback URL and getting a response

Is there any way to get drafts://x-callback-url/runAction to return a response in the x-success parameter?

I’m tinkering with OmniFocus plug-ins using Omni Automation and I’m finding cases where I want to make use of Drafts actions as part of the plug-in implementation, simply because there are things that Drafts does really well that Omni Automation doesn’t cover.

My current goal is to write an OmniFocus plug-in that will automatically create a new note in Bear for the selected project and then copy the Bear link back into the OmniFocus project note field. I can probably make this work without involving Drafts at all, but I’d really like to be able to delegate the note creation to a Drafts action so I can use MustacheTemplate and Drafts’ CallbackURL object.

The only problem is that I don’t know how to get the Bear note link back to OmniFocus in the x-success parameter. What I’d really love is a function in Drafts Scripting API that would let me set the x-success response from the action — maybe on the Context object?

What does the Omni Automation end of that transaction look like? Do they have an object that is similar to Drafts’ CallbackURL that waits on a response and gives you access to those parameters?

1 Like

They have a URL object with a call function that takes two callback parameters — one for handling x-success and another for handling failures. Not as nice as Draft’s CallbackURL (I really appreciate that CallbackURL does the heavy lifting on URL building and encoding), but serviceable.

I have a version of my plug-in implemented that just goes straight to Bear rather than using a Drafts Action, which you seen look at to see an example of the Omni Automation call function in action:

Gotcha…and, in the meantime I added something to support what you need for the next release. It was a really simple tweak.

The next beta build will have a new context.addSuccessParameter(key, value) method you can use in actions to assign query arg params that will be included in the x-success callback of /runAction. If you want to test it out, feel free to get on the beta (not in current build, but will be in next update).


Wow! Thank you, that’s awesome. I’ll give it a try.