Updating a yaml value with a hotkey

I have a yaml variable called “check”, which contains a date, which I update with the current date once I feel I have adequately updated a note.
At the moment I update this by having check always be the first attribute in the file:

---
check: 2024-03-01

I run an AHK script to go to the top of the file and change it. This is gross, but for now gets the job done.

I would like to be able to accomplish the same thing with a hotkey, and I would like it to not be dependent on the variable’s position in the yaml – or even its presence, if it comes to that.

What’s the easiest way to accomplish this? I am somewhat familiar with templater and dataview, and have installed metadata menu but do not understand how to use the api and cannot find an example that does the above.

Any help would be greatly appreciated!

I’d use await app.fileManager.processFrontMatter() to do the actual updating, and then it’s up to you to choose how to trigger it. It is not a problem to do this from a multitude of alternative plugins, but since you’ve already got Templater installed, one option is to make a small template which doesn’t actually return anything, but just executes a call to update your value.

So maybe something like the following:

<%* 
const newTime = tp.date.now("YYYY-MM-DD[T]HH:mm:ss") 
await app.fileManager.processFrontMatter(tp.config.target_file,
  fm => { fm.check = newTime })
_%>

Assign this template to a hotkey, and you should be good to go. At least, after you adjusted the date format to your liking. :slight_smile: Try it out with this variant, as it easy to see that it’s working alright…

2 Likes

holroy does it again. It works perfectly!
thank you very much :slight_smile:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.