How can I retrieve the front matter in my script?

Hi all,

I’m very new to Drafts, so this might be an ignorant question. However, I can’t find anything in the scripting reference about how to retrieve Markdown frontmatter.

There are references to it in the multi markdown object, and the MultiMarkdown settings, but I don’t see a way of programmatically retrieving the information.

What am I missing?

Thanks!

Drafts does not have any special handling of front matter. Is there a particular value or values you are trying to extract? It’s not terrible hard to pull values out of in script.

Ah, can you educate more on the usual Drafts patterns? I have looked around but can’t find something that does quite something similar to what I’d like to do.

As an example, let’s say that I want to use the Gmail action step. However, instead of hard-coding the “to” field, I want to extract it from the draft.

I was asking about front matter because I assumed that there would be a function that turns values into an object that I can easily read from. However, is there a better pattern to do this? Is there an action you can refer me to that does something similar?

Thanks!

Most Drafts action steps use templates to generate values used in the action. Typically, the way that would be configured in Drafts is to have values separated by line, and use a [[line|n]] tag to get that value in the template.

For a Gmail action, that might mean you have [[line|1]] as the subject, [[line|2]] as the “TO” field, and [[line|3..]] as the body template value - meaning the first line would be the subject, the second line the email of the “TO”, etc.

More on templates in this article.

2 Likes