Drafts Markdown to PDF with Date (Draft) Created

Hello, Automators!

I am looking for help in creating either a Drafts action or a Shortcut that will enable me to convert a Markdown Draft into a PDF with the date that the Draft was created (not necessarily the date that the PDF was created) as a part of the file name.

I’m the dad of a Suzuki violin student, and I sit in on all the lessons and take notes on my phone in Drafts. I want to be able to save these notes as PDFs (which I can do no problem), but with the date of the lesson in the file name. If I always remember to file them on the day of the lesson, I can just use “today’s date” variables. But alas, that doesn’t always happen.

Any help would be appreciated. Thanks!

-Eric

I’m new to this, so there may be a better way, but here’s a shortcut that I think does what you want?

https://www.icloud.com/shortcuts/102a4b5ee03a47eabe1792fb0082e39a

The “Get Draft” Shortcuts action requires you to know the UUID, which you can copy to clipboard from Drafts. The shortcut then grabs that, gets the draft, renders the markdown, sets the PDF name and previews it. Obviously you could change it to save the file somewhere, etc.

1 Like

Rather than a single option, I’m going to suggest an option that utilises both an action and a shortcut - so you will need to download/install both of the following.

As it stands the action doesn’t archive, but you could set the switch for that if that’s indeed how you are tracking the processing of your notes.

Since you didn’t actually specify the format and content for your PDF, I’m providing this purely as an example to illustrate how it can be done.

In the Drafts action it is simply a call to the Shortcuts shortcut with the following template.

[[created]] [[title]]
[[body]]

The first line is going to be used for the file name. It contains the draft creation date (formatted to yyyy-mm-dd by default, which is a good way to date stamp file names), followed by the draft title, which is the first line of the draft. The second line is the body of the draft, which is every line after the first.

This could actually be expressed identically as [[created]] [[draft]], but I figured this would simply be more explicit if I called it out with the above :wink:

The shortcut splits the input up by lines and takes the first line of the input it receives to use for the file name. The subsequent lines are recombined, and run through a Markdown to PDF conversion. The resulting PDF is named and passed to a save as file step

Once saved, Shortcuts should hand back to Drafts.

Hope that all makes sense.

3 Likes

That looks awesome! I didn’t know about the [[created]] tag in Drafts! I should be able to play with this and make it work for my use case.

Thank you so much! I really appreciate the assist.

-Eric

The following page describes the many available template tags.

https://reference.getdrafts.com/topics/templates.html

1 Like