"Button" to modify front matter

Hey all,

In most of my tasks, I’ve got front matter looking akin to:

created: 2021-06-06
assigned: 2021-06-06
dueDate: 2021-06-09
todoDate: 2021-06-07
inprogressDate: ""
doneDate: ""
status: 2
  - ❔ Created
  - 📆 Scheduled
  - ⚙️ In Progress
  - ✅ Complete
  - ❎ Will Not Do
class: MAT220🧮
task: "Data Visualization"

I then use dataview to render tables of tasks with their various traits. It’s quite nice!

I’d like to streamline things, though by being able to graphically update the status number. As it stands, I wind up needing to count to be sure in most cases, which is lame and slow. =)

So I wrote this little python script:

#!/usr/bin/env python3

import sys
import frontmatter
import os

if len(sys.argv) != 2:

current_filename = sys.argv[1]
desired_status   = os.environ["desired_status"].lower()

if len(desired_status) == 0:

with open(current_filename) as current_file:
	post = frontmatter.load(current_file)

	desired_index = -1

	for index, status in enumerate(post["statusList"]):
	    if desired_status in status.lower():
	        desired_index = index

	if desired_index != -1:
	    post["status"] = desired_index
	    print(f"Could not find status '{desired_status}'.")

And put it into action with this here Buttons button:

name Mark Complete
type line(1) text
action <% tp.user.update_status({desired_status: "complete"}) %>
replace [1,0]
templater true
color blue

It doesn’t work quite, as it winds up appending everything. I tried using replace [1,1000], replace [1,-1], and replace [1,0] but it seems like Buttons wants exact line numbers.

So… thoughts? Is there a simpler way to graphically run a Templater command? Or maybe there’s some way to run Templater commands via hotkeys?

I’m open to whatever solution. =) Thanks in advance!

1 Like

Can you post your dataview queries please? :slight_smile:

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