[Pending] Run Drafts Action shortcut and data passed to Drafts


I want to implement the following end user workflow. Hit the share button something that will produce a URL, and have that url directly appended to a draft with a particular tag. I’ve been trying to do this via a Siri Shortcut that turns around and uses the Run Drafts Action to invoke a Drafts action. The Drafts action has a single Javascript step. My JS code finds the correct draft and can append some dummy text to it, but I cannot figure out how to take the URL that came from the Share Sheet and Siri Shortcut, and access it in my JS code.

If I understand what you are trying to do, I think you could just create a one step Shortcut in the Shortcuts app that used the “Add to Draft” action in Shortcuts. Set it to append, and enter the UUID of the draft you want to target…then make that shortcut available in the Share sheet.

The problem is that I don’t want to hardwire the UUID of the draft. What data does the “Run Drafts Action” shortcut pass to the drafts action that it runs, and how do I access it? A pointer to the right page of documentation would be fine.

The input from Shortcuts when using “Run Action” is the text of the draft as if you had typed it in Drafts and run an action. So in templates you can use any template tags to use that text, or in script using the Draft object - notably the draft.content will be the full input string passed from Shortcuts.

1 Like

That’s what I was missing. Works great!

1 Like

I have an action (a script I wrote) that runs flawlessly within drafts. But when run through shortcuts (run an action on a draft) the results are erratic. Any suggestions for what’s happening here? My script uses draft.content to pull the text of the draft. When run within drafts it appends to the designated draft; Through shortcuts it usually appends to a completely new draft.

Hard to say without example shortcut & action. Could you share? At least a screenshot of the pertinent part of the shortcut?

Oh it’s literally a one step shortcut.

Run action —— on draft ——-

Nothing else.

Still a lot of variance it how your drafts action is written and how you have the shortcut configured. How are you targeting the draft you append to in your script? Just sharing your Drafts script might be helpful.

From Shortcuts, the action to run an action on a Draft, you have to specify the draft to run on. When you run it in Drafts, you’ve noted that it is the current draft, but you haven’t given any indication of how you are specifying the draft to run against in Shortcuts. That’s going to be a key aspect to this as if you are setting that in a way such that the draft doesn’t always exist, then that could be an explanation for the behaviour … and given the action woks reliably in Drafts, my gut feel would be to check that.

I found the solution in agile tortoise’s answer in a separate thread which fixed it for me. Delighted to be up and running again!

Is your Start action using an “Insert Text” action step? If so, this is expected behavior…even if a bit counter intuitive.

The reason being the “Insert Text” step interacts with the editor, not the draft, and the draft you are running the action on is not loaded in the editor when triggered in this manner. The same affect would be present if you use the /runAction URL scheme…and would have similar outcomes if the action was scripted and used editor functions to manipulated text in the editor instead of in the draft directly.

This is something I debating implementing these shortcut actions, but to avoid it would mean that running the shortcut would have to load the draft in the editor, ignoring whatever you currently had loaded. It’s possible that behavior makes sense now, when the shortcut action has to launch the app to operate, but if the shortcut action was able, in the future, to run in the background, there would not even be an editor to interact with.

You could force Drafts to load your draft and get the result you are expecting by scripting it in your action. Before the “Insert Text” action step you added a “Script” step with the following:


That would force Drafts to load that draft in the editor to be manipulated.

(Problem with Shortcuts' "Run Action on Draft")

Sorry I’m new to use schortucs, how to add this step exactly (Which acttion to pick in Shortcuts)?

So this code is in a custom Drafts action which you can code using Javascript.

Then in Shortcuts you just call the Drafts action and run it on the specified Draft. It looks like this: