iOS Shortcut "Run Action with Text" (magic variable?)

Drafts newbie here. Also iOS Shortcuts newbie. Apologies in advance for likely naiveté.

What I would like to do: Create an iOS Shortcut, available in the share sheet, that takes as input any text and removes any empty lines. My intuition is that I can do this using Drafts.

What I have tried: I found the action Single Space in the Drafts Directory and installed it; it works when invoked directly from Drafts. Then, in the Shortcuts app, I attempted to create a shortcut, as follows:

  1. I add the Shortcuts Drafts action “Run action with text,” selecting Single Space as the action and Shortcut Input as the text.

  2. I add the Sharing action “Copy to Clipboard,” attempting to use the output from (1) as the input…but at this point the trail goes cold. When I open the magic variable picker, there is no magic variable available for “Run action with text.”

Am I doing something wrong? Is there any other way to capture the output from “Run action with text”? Any other advice?

Many thanks!

I’m not exactly sure from your description why you need to use Drafts for this. Shortcuts is capable enough. Here’s a couple of quick examples:

You should be able to convert them to share sheet use easily enough.

In regards to this specifically, if you look at the information for the action in Shortcuts you’ll see that the result is “(Text) The Input”, which should mean whatever preceded it is also what comes out of it. But similarly I don’t see this surfaced in magic variable selection. But if you had copied to the clipboard, you would be able to access the system clipboard, which is a standard variable.

1 Like

Many thanks, that’s very helpful. With regard to the result of “Run action with text,” I understand from your response that the result is what was input, before the action was run. I’m obviously missing something, but why wouldn’t one want to capture the consequence of the action? And how could one in any event? I’m afraid I don’t understand “if you had copied to the clipboard,” as there doesn’t seem to be any result from “Run action with text” that is available to later Shortcut actions.

Here is a slightly more elaborate use case, to illustrate what I am hoping to do more generally. The typical BibTeX reference generated by Google Scholar capitalizes only the first word of the title. By hand, I could a) copy the BibTeX reference, b) paste into a new draft in Drafts, c) run the Title action, available from the Drafts Directory, d) copy the transformed text in Drafts, and e) delete the draft for good housekeeping. My intuition, again, is that I should be able to do something similar from an iOS shortcut using the “Run action with text” Shortcuts action, but that doesn’t seem possible…?

Thanks again for any assistance!

And, I should say, maybe there is a way to do this also directly from iOS shortcuts, but I don’t know enough scripting to do so. I would like to be able to take advantage of the action already written for Drafts. Thanks!

  • Shortcuts can do that.
    • Split the text by lines: Split Text Action.
    • Take the first line: Get Item From List Action.
    • Title case the first line: Change Case Action.
    • Join the lines again: Combine Text Action.
  • You can use the clipboard to transfer data between apps even when there’s no return in Shortcuts.

Where is your text originating for this latest example? Is it sill round tripping via the share sheet?

Many thanks: this is illuminating. I think I am close. The only thing I cannot figure out—and I apologize; I have tried—is how to put the line with the changed case back into the original position. (The title is always in the second line.) This shows both my attempt and the outcome:

Okay, having the title as the second line complicates things a little. I’d perhaps have suggested a repeat loop instead, but it is still possible to rebuild it based on the previous discussion.

This might give you a few more ideas.

Hope that helps.

I think I got it.

Interesting to see your approach. Thanks for all your help! I really appreciate it.

Actions don’t have a return value. It’s not at all clear what an action would return to Shortcuts, and the APIs to return values are a bit limited at the moment and not flexible about returning different types of values.

You happen to have an action that modifies text, but that’s not really typical of what actions do in Drafts.

There are many ways to get a result back to Shortcuts. The Drafts action could put text in the cllpboard, as @sylumer mentioned, but also write to files, or store results in a draft which could be fetched. Lots of options.

1 Like

Many thanks: this is really very helpful.

(Hopefully I’m reviving this thread in a way that might prove useful to others.)

I understand that the task the OP was hoping to accomplish can be done without Drafts, but regarding this quote about the “Run Action with Text” Shortcuts action, I’d just ask: how?

As in, how exactly would I go about getting the action’s output into the clipboard/a file/a fetchable draft/etc?

Apologies if I’m missing something here… and thank you!

Do you have a point A and point B in mind? It’s often a lot easier to suggest the right approach with a specific goal.

For the clipboard? There is the “clipboard” action step that can place text in the clipboard, but also clipboard scripting methods.

For Files? Similar. There are “File” action steps that can write text to files, but also ways to script writing files.


1 Like

Specifically, I was hoping to add a function to my “Collect References” Shortcut (which outputs all hyperlinks from a given article/webpage as a list of raw URLs) which grabs titles for each respective URL and formats them as proper Markdown links ([title](url)) using this “Replace URLS by MD Links” Drafts action from the action directory.

As per the screenshot below, I suppose I’m looking for the correct action in place of “Copy to Clipboard” which handles the result of said Drafts action, if possible.

The action you reference is updating a draft. That is its output.

Either you change the action to do something else, or do more (such as put the result on the clipboard), or you want to get the content of the draft after the action has run against it, in which case you would be looking at a Get Draft step in Shortcuts.

The action updates a draft’s content by replacing URLs with Markdown links. But it looks like you are passing in a Markdown formatted link you want to be updated. To me it looks like you are using the action incorrectly.

If you stay in Shortcuts, Get URLs From Input on your original text, then for each (I.e. Process in a repeat with each loop) unique URL, use Get Contents of URL, you can build each Markdown link and replace it in the original text with Replace Text. I’m not sure in this instance where Drafts is going to give you the edge in automating what you seem to want to do.

Hope that helps.

1 Like