"Drafts Action Templates" - *ThoughtAsylum* #98
Labels
actions
Drafts Actions!
documentation
Improvements or additions to documentation
reading
social
Regarding the community.
templating
Style, configuration, and fornmat templating for Drafts.
30 Sep 2022
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](https://getdrafts.com/). 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.
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.
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.
The text was updated successfully, but these errors were encountered: