With the release of Apple’s new Shortcuts app, a world of automation possibilities have been opened on iOS.
Drafts can trigger Shortcuts app shortcuts using the Run Shortcut action step. It can also get a text result from a shortcut, and insert that result text in the current cursor position by combining a Run Shortcut step with the Insert Text action step. Keep reading for an example of this in action and steps to customize for your own shortcuts!
Inserting results from a shortcut can be very useful to send text selections to Shortcuts to be manipulated, to insert template text, or insert data loaded or imported from other sources supported by Shortcuts.
To test this out with an example, install the following items:
- Insert Color Drafts action: Example action which triggers the “Select Color” shortcut by name and inserts the result.
- Select Color shortcut: This is a simple shortcut which prompts you to select from a list of colors, and returns the select color. Click link above to install into your Shortcuts app.
Details and Customization
The above example can be modified to use a different shortcut by changing the “Shortcut name” value in
Run Shortcut step of the action, but a more complete explanation of what is going on follows:
This action contains two action steps:
Run Shortcut: Runs a shortcut by name. To change the shortcut being used, simply edit the “Shortcut name” to match a valid shortcut installed in your Shortcuts app. The step also has a couple of settings you may wish to configure:
Template: Controls the text sent from Drafts as an input to Shortcuts. If your shortcut does not use the input text, this value can be ignored. The template accepts any Drafts template tags, and the example defaults to the
[[selection]]tag, which sends the currently selected text only.
- Wait for response: For this action to work, it is important that wait for response be enabled. This tells Drafts to pause the action and wait for the result of the shortcut to be returned from the Shortcuts app.
- Template: Controls the text sent from Drafts as an input to Shortcuts. If your shortcut does not use the input text, this value can be ignored. The template accepts any Drafts template tags, and the example defaults to the
Insert Text: This step inserts text in the current draft, as if you pasted it from the clipboard. It will replace an existing selection, or insert new text at the last cursor position. The
Insert Textstep also has a template which uses template tags. In this case, it is using the
[[shortcut_result]]tag, which is a special tag which will contain the result returned from the most recent