Action to add today's date as title?

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

This worked great, thank you!

1 Like

Will this do a short date format? For example: 12-18-20

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: