Drafts has a robust action framework do many tasks, text manipulations, etc., but sometimes it is useful to call out to Apple’s Shortcuts app to perform such functions. Perhaps, you are just more comfortable with authoring Shortcuts, or the actions in Shortcuts allow you to pull information from other apps that is otherwise unavailable to Drafts.
Today, I’m sharing an example action that is setup to do the following:
- Get the selected text from the editor
- Send that text to a shortcut of your choice as input
- Receive a result from the shortcut
- Replace the text selection in the editor with the result
This example action is reusable, because it uses Drafts’ new action configuration options to change the name of the shortcut to use.
The example also demonstrates an advanced techniques for calling a shortcut. On iOS, the only way to call a shortcut from another app is via x-callback-URL – as a result, the Shortcuts app will come to the front and return to Drafts. On iOS, this action uses Drafts convenience Shortcut
object to make that call. On Mac, however, it is possible to call a shortcut in the background without opening the app using AppleScript. This example action does that when running on Mac for a smoother experience.
Demo Video
Here’s a walkthrough of the setup process:
Setup
To use this example, do the following:
- Install the Shortcut: Insert Result example action from the Directory
- Identify the shortcut you wish to use. It can be any shortcut installed in your library that:
- Accepts text as input
- Ends returning a text value
- To test this setup, you can install and use an example UPPERCASE shortcut. This is a simple example that takes the input text and converts it to UPPERCASE.
- Run the action. On first run, you will get a configuration prompt, asking for the name of the shortcut you wish to call. You can change this later in the action configuration.
- After configuring, select the text in the editor, and run the action again. Your shortcut will be called, and the selected text replace with the result. If using our UPPERCASE example shortcut, say, selected text of “test” would become “TEST”.
That’s it. You can create shortcuts that do anything - pull data from other apps, format the content, whatever. If you have multiple shortcuts, simply duplicate this action and configure each instance with a different shortcut name (and, probably, edit the action name for identification purposes).