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.

Many thanks: this is really very helpful.