EduGon
December 15, 2020, 7:30pm
1
Hello! I’m new to Drafts and I has running into some issues trying to program an action in order to add the current date as a draft’s title.
Ideally, I would like to be able to quickly capture a thought, and then click on the action button to format it as I want. Here’s what I’m thinking:
Going from a draft with text (left) and after hitting an action button above they keyboard, turning the note into one like in the right.
I’ve been struggling to this and would love to know if any of you had any ideas.
Thanks a lot in advance! What an app!
Several ways to accomplish this…probably most straightforward if you are wanting to do it after you capture the text, would be a two step action. The first step a “Define Template Tag” step with the tag name template
and following template:
[[date|%e %b, %Y]]
[[draft]]
That just creates a template that is the date, and the current content of the draft. Then in a script step:
draft.content = draft.processTemplate("[[template]]");
draft.update();
Which sets the text of the current draft to the new value as passed through the template.
1 Like
EduGon
December 15, 2020, 8:44pm
3
This worked great, thank you!
1 Like
glor
December 19, 2020, 5:33am
4
Will this do a short date format? For example: 12-18-20
sylumer
December 19, 2020, 9:24am
5
Yes. That example would be expressed like this [[date|%m-%d-%y]]
.
1 Like
If you’d like more detail on how formatting dates works, there’s a section on dates/times in this article on using templates:
Template Basics
Drafts actions consist of “steps.” Action steps are available for a wide range of functions and services: Sending messages, mail, saving files, and much more. Regardless of the purpose of the step, any step that output information has some fields that allow you to control what text the step uses, and (with a few minor exceptions) use templates to dynamically generate that text.
If you have poked around in the action editor and wondered what some of those [[title]] and [[body]] …