Drafts Action Templates

There was a recent discussion on the Drafts Slack group (used mainly by beta testers), about action editing and I shared a little trick I use for creating action templates that give me a quick start. In this post I’m going to outline the approach that will hopefully also save you time on creating new actions.

What is an Action Template?

There are no official templates for actions in Drafts. When you create a new action, you simply start from the application’s empty action (no steps), with the default settings.

I have some actions set up that on their own, do nothing useful, but they do make good starting points for the sorts of actions I create. For example an action with a single script step (with the default comment removed), and the logging levels set to my own personal preference. These are my templates.

Using an Action Template

The easiest way to use action templates is to use the inbuilt option to duplicate them. This is available when you swipe the menu on iPhone/iPad, and on the context menu when you right click on an action on the Mac.

When you duplicate an action, the new action is placed after the duplicated action with “ (copy)” appended to the name.

This is really useful, but you have to navigate to wherever you store your template actions (I would suggest an additional action group), duplicate the action, modify the action and then move the action to where you want it.

If I’m building out a new set of functionality within an action group I often use this sort of approach when I’m building a series of actions that could be described as variations of one another. It is an efficient way to do it.

However, if I am creating a single action, or a set of unrelated actions, I fall back to another approach which is more convoluted to set up but I find makes the process a little easier to set up in the long run.

Using an Action to Create a New Action

Actions are available anywhere and can be triggered by a keyboard shortcut or added to an action bar. By tying the creation of a new action to an action, we can make it easily accessible, and you can even build an action that offers up a list of templates to choose from if you find you have several you want to choose from via a single trigger.

On that basis, the question is how do you make an action that creates an action?

As well as sharing actions via the action directory (absolutely the easiest way), there is an option on actions to share them as a URL. For your desired action, look for the share option.

On the iPhone and iPad you can find it by the action name when editing the action.

On the Mac, it is found in the share section.

When you select to share, you will see an option to choose between a file and a URL.

The options look like this on iPhone and iPad.

The options look like this on the Mac.

When the URL option is selected, it copies an installation URL to the clipboard. It will look something like this.

drafts://action?data=%7B%22uuid%22:%22FB02BDB5-B3B4-4E63-B22B-C660D336C001%22,%22steps%22:%5B%7B%22platforms%22:3,%22data%22:%7B%22script%22:%22%22,%22allowAsync%22:%22false%22%7D,%22type%22:%22script%22,%22isEnabled%22:true,%22uuid%22:%222C19C22D-D9F4-464E-BB14-9A983EC220E0%22%7D%5D,%22backingPlatforms%22:3,%22shortName%22:%22%22,%22shouldConfirm%22:false,%22disposition%22:3,%22keyCommand%22:%7B%22optionKey%22:false,%22input%22:%22%22,%22controlKey%22:false,%22commandKey%22:false,%22type%22:%22action%22,%22discoverabilityTitle%22:%22New%20Script%20Action%22,%22shiftKey%22:false%7D,%22logLevel%22:1,%22groupDisposition%22:0,%22notificationType%22:1,%22tintColor%22:%22none%22,%22actionDescription%22:%22%22,%22keyUseIcon%22:false,%22icon%22:%22%22,%22visibility%22:480,%22backingIsSeparator%22:false,%22groupUUID%22:%22C8AA8199-DC6A-41D6-8285-C9F2F7F7F13A%22,%22assignTags%22:%5B%5D,%22name%22:%22New%20Script%20Action%22%7D

This is actually the URL I most commonly use. If you take the content of the data parameter, URL decode it and format it as JSON, you can see the raw structure of the action in more detail.

{
  "uuid": "FB02BDB5-B3B4-4E63-B22B-C660D336C001",
  "steps": [
    {
      "platforms": 3,
      "data": {
        "script": "",
        "allowAsync": "false"
      },
      "type": "script",
      "isEnabled": true,
      "uuid": "2C19C22D-D9F4-464E-BB14-9A983EC220E0"
    }
  ],
  "backingPlatforms": 3,
  "shortName": "",
  "shouldConfirm": false,
  "disposition": 3,
  "keyCommand": {
    "optionKey": false,
    "input": "",
    "controlKey": false,
    "commandKey": false,
    "type": "action",
    "discoverabilityTitle": "New Script Action",
    "shiftKey": false
  },
  "logLevel": 1,
  "groupDisposition": 0,
  "notificationType": 1,
  "tintColor": "none",
  "actionDescription": "",
  "keyUseIcon": false,
  "icon": "",
  "visibility": 480,
  "backingIsSeparator": false,
  "groupUUID": "C8AA8199-DC6A-41D6-8285-C9F2F7F7F13A",
  "assignTags": [],
  "name": "New Script Action"
}

Assuming you retain the action, the URL when executed will trigger an installation, prompting you to overwrite the existing action of this name or import it as new. If you delete the original action (you can always get it back with this URL if you want to amend it and generate a new URL), you won’t get this prompt.

Next you will be prompted for which action group to create the new action in. Upon selection, Drafts will import the action into that action group.

You can store and trigger such a URL using the URL step in a Drafts action, which allows us to take advantage of the action points I referenced earlier.

Therefore, if you create your template action, export the URL, place it into the URL step of another action (for creating new actions), and delete the original template action, you will get an action that when run will prompt you where to create your new action from template.

Conclusion

For anyone who regularly creates Drafts actions, this is a big time saver. While I still use the inbuilt duplicate method regularly, the ad hoc creation of actions and the creation of new actions that are dissimilar to other actions in a group are where I get a lot of use out of the rather meta, action template installed via an action approach.

If you really get into it, knowing something about the JSON above (and being able to read it from exporting any action), you can start to build more complex template and dynamic template actions too. You can generate your own UUIDs, build an HTML user interface to allow you to build up your own content to dynamically build into a URL, etc.

Hopefully, you will find this general method useful, and can tailor it to your own needs.

Author: Stephen Millard
Tags: | drafts |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read