Send to Obsidian — with tags and YAML metadata

I’ve just added an improved version of a “Send to Obsidian” action. The improvements:

  • The note’s name is either the heading or the creation date-time, depending on the drafts beginning with a header or not.
  • A YAML header is added with the creation date and time of the draft.
  • The tags are written at the end of the note, under a separator line.
  • The vault name is an editable constant.

In practice :

  • If you start your draft with a #, it implies that the first line is a header — it doesn’t matter how many # there are.

    • In this case, the filename of the Obsidian note is derived from the header.
  • If the first caracter of the draft is NOT a #, the first line won’t be the note’s filename. Instead, the filename will be the creation date and time of the draft, in ISO format.

In any case :

  • A YAML metadata header is added at the top of the note, with an entry with the creation date and time of the draft.
  • The draft tags are added at the bottom of the note, below a separator line.

In the Directory, the action is → here ← .

Olivier Spinnler

6 Likes

Very nice.
You have couple of design decisions I’d like to understand the why of:

  • Why add the metadata front matter to the Drafts content? Doesn’t that muddy up the display title?
  • Why not put the tags in the metadata instead of appending to the end?

Being somewhat new to both Drafts and Obsidian, I may not be aware of legacy or best practices which might explain these practices.

Are you suggesting skipping the metadata? If not then the metadata has to go at the front.

The meta data is generated from the draft. It has to go at the front of the Obsidian note, but it doesn’t have to go at the start of the draft; but the action looks like it probably modifies the draft too.

In Obsidian, it’s own default tagging approch is to include hashes terms in the body. These hyperlink to a tag search. Meta data for tags in the YAML do the same, but when you search you don’t see them in context in the results. I think that can add value, but adding them to the end vs adding them to YAML at the start I don’t think offers any difference, other than meta data can be hidden, and I don’t think would appear if published - but I don’t use the publishing service, so I don’t know for sure.

Are you suggesting skipping the metadata?

No, I’m suggesting the front matter goes only to the Obsidian side of things leaving the Draft side unaltered. Sorry for not being clear on that.

the metadata has to go at the front.

Yes, in the Obsidian note, probably not in the draft. In the draft this metadata has no value I know of. Do I have that wrong?

1 Like

Yes, if the #tag #list is added to the end of the document the placement context is effectively lost. In that case it seems desirable to put those tags in the metadata where they can be hidden. This could also be used in some automated Obsidian to PDF action.

That’s correct: In the draft it has no value - as Drafts doesn’t do anything with it (including when rendering). Other Markdown processors, however, might well do.

Sorry to be a dumbo … new to obsidian … not new to drafts and have edited action steps in the past - but for life of me can’t get this to work.

What are the variables I need to change to make this work?

Thankyou in anticipation.

Looks like it should just be vaultName. It is using thr Obsidian URL scheme, and so just needs the vault name registered in Obsidian to be able to match to.

Thankyou - yes I thought that and it just wouldn’t play nice. But with your thought I kept modifying and found the error … the credentials were hanging around from an earlier experiment - now working.

Much appreciatrd

Paging @OlivierPS

Thankyou for this - very nice. I haven’t playing around a bit and very much living what I find. Sometime tho I have noticed that the action ‘stops working’ …

I repost the same draft just to experiment ,

In drafts it is as if once a draft is posted - it won’t post again?

But if I reset the draft it is all ok again.

Is that correct behaviour? I can understand why - just wondering

If you post with a level 1 heading draft as the title it will recreate the same file. If no such heading is present it will post with a timestamp as the file name. The timestamp is down to the second, so for a single draft I think you would alway get a unique file name and thus a new file.

Does that explain the behaviour you see? If not, can you provide more detail on the behaviour you see?

How do you “reset” your draft?

should be better - essentially copy the whole thing into a new note

i have pushed and prompted and persevered - and getting there. it still seems that SOMETIMES - if there i no header - the draft doesn’t post to obsidian - but not always - sometimes as you say - a tie stamp is there … i cat get anything repeatable right now though.

When i do i wil be back - my thank for your help

This thread seems to be most relevant and I’m looking for any advice. I want to include a TAG with an ACTION that sends DRAFTs note to Obsidian. I want that TAG to populate the “front matter” and appear at the top of my Obsidian Note (where properties are displayed if you toggle them on) but can’t figure out what I’m doing wrong. I’ve tried entering my tag with and without a hash tag. The creation date sort of works (had to click it to display correctly), but the TAG doesn’t at all. Would appreciate any recommendations.

Attached is a snapshot of of the ACTION (pulled from ACTION DIRECTORY) and then modified. There is a snapshot with and without hashtags. Also attached is the resulting Obsidian note. Notice the TAG property is empty.



I think with the Tags field in the File action step you’re creating a tag on the file (in finder / apple files app). The [[tags]] you use in the template only processes tags from the actual draft.
I assume your draft does not have any tags and that’s why the Obsidian note doesn’t get populated with tags.

1 Like

Dang it! @FlohGro, you’re right! It’s tagging the file in the FINDER! I’m coming from DRAFTS ACTION that added a default tag named “call log”when it created an Evernote note.

Sounds like you’re saying I’ll have to insert the TAG “#call-log” in my formatted note to have it picked up. An extra step and I will have to get use to seeing the HASTAGS in the drafts note now. I’ll start testing to see if this approach places the TAG in the property section. Thanks for hunting down this tag.

You could just replace the [[hastags]] with #call-log or whatever tag you want to use in your obsidian note :slight_smile:

A tag in Obsidian is not a tag in the finder / the file itself.
It’s just confusing since the naming overlaps :joy:

When I try entering the tag in the TEMPLATE, it still doesn’t transfer. Maybe I missed your point:


tags: #Call-Log
date: [[created|%Y-%m-%d]]

Or


tags: Call-Log
date: [[created|%Y-%m-%d]]

Both end up with the date working but not the TAG. If you meant ADD the TAG in the physical draft each time or CLICK on my DRAFTs note TAGs, and add back [[tags]] in the template…that works. However, I was trying to avoid the extra step.

Placing it in the body of the note will transfer, and appears to create the TAG, but the tag won’t populate the PROPERTY section (front matter).

I think your tags should be formatted as a YAML list as covered in the Obsidian docs for the tags property in the note front matter.

Setting up an action like this:

Then using a draft like this:

# Call Log Example

Spoke about X

Spoke about Y

Spoke about Z

Gives me a note in Obsidian like this:

If you (or anyone else), did want to transfer Drafts tags to Obsidian tags, adding a script step like this ahead of the file creation:

let strTags = "";
if(draft.tags.length > 0) strTags = "\n" + draft.tags.map(x => "  - " + x).join("\n");
draft.setTemplateTag("YAMLTags", strTags);

 
Means you can then use this line in your content template to put the Drafts tags in as Obsidian tags.

tags:[[YAMLTags]]

 
Hope that helps.

1 Like