You can use the metaedit plugin.
I made a script where it updates the frontmatter and “completes” a habit by adding a “” emoji. The script takes a completed “true” and “false” argument: it removes this “” emoji from the frontmatter. I create 2 templater notes so I can tie those to a button from the buttons plugin.
Perhaps my code can help you out for your project:
Frontmatter in my daily note:
---
habits:
- uhive::
---
Templater notes
Change Metadata Uhive
<% tp.user.change_metadata(tp,app,"uhive",true) %>
Remove Metadata Uhive
<% tp.user.change_metadata(tp,app,"uhive",false) %>
Templater script file
change_metadata.js
async function my_function (tp,app,habit,completed) {
const filetitle = tp.file.title
const file = tp.file.find_tfile(filetitle)
const {update} = app.plugins.plugins["metaedit"].api
if(completed == true) {
completed = "✔️"
} else if (completed == false) {
completed = " "
}
await update(" - "+habit,completed,file)
console.log("Finished")
}
module.exports = my_function
Optional: button configuration from buttons plugin
Change metadata:
```button
name Uhive
type command
action Templater: Insert Obsidian Vault/Templates/Templater/Metadata/Change Metadata Uhive.md
color blue
class button
\```
^button-uhive
Remove metadata:
```button
name Pinterest
type command
action Templater: Insert Obsidian Vault/Templates/Templater/Metadata/Remove Metadata Uhive.md
color blue
class button
\```
^button-rmuhive
Swap button which swaps between both buttons up here
```button
name Uhive
swap [uhive,rmuhive]
color blue
class button
\```
^button-swapuhive
Now you can use button-swapuhive
in your daily notes and the button will update + remove the “” emoji when clicked.
Optional: Display the metadata beneath the inline button we just created in a table
This is a code block for the dataview plugin
```dataview
table without id
date.day as "Day",
habits[0]["uhive:"] as "Uhive"
from #daily and -"Template"
where date = date(2022-03-14)
sort date
\```
Sorry if I went overboard with this, my script goes even deeper than that, but I guess this might already be overwhelming.