I kept on thinking about this, and decided to expand the template a little, and give it some more options, and I ended up with this template:
<%*
const consoleDebug = true
let sel = tp.file.selection()
newStatusDict = [
["Cancel task", "-", "canceled", true ],
["Task in progress", "/", "started", true ],
["Complete task", "x", "completion", false ],
["Complete task ✅", "x", "✅", false ],
["Clear the task", " ", "removeComments", false ],
]
const newStatus = await tp.system.suggester( t => t[0],
newStatusDict, true, "Choose new status")
// Some debugging and extraction of values
if ( consoleDebug ) console.log("newStatus\n", newStatus)
const [ name, status, fieldName, useComment ] = newStatus
// Set status to new value
sel = sel.replace(/\[.\]/, `[${ status }]`)
// Define the field
if ( fieldName != "removeComments" ) {
const optComment = useComment ? ' %%' : ''
const field = fieldName.length == 1 ?
` ${fieldName} ${ tp.date.now() }` :
` [${fieldName}:: ${ tp.date.now() }]`
sel += optComment + field + optComment
} else {
// Remove any comments, if that's the wanted action
sel = sel.replace(/%%.*%%/, "")
}
// Replace the selected part with our modified version
tR += sel
%>
Some explanation of the template
- It’s prerequisite of the template that the entire line with the task is selected
- The
newStatusDict
holds the various actions available, where each action consists of four elements:
- The name of the action used in the suggester
- The new status character used within the
[ ]
- The field name used to mark the new task status, either a field name or an icon
-
true
or false
depending on whether the field should be enclosed in comments or not. If enclosed it’ll not show up in reading view
- So present the actions to the user for selection, and do some variable manipulation to ease the rest of the template
- Always set the status to the new status character
- I’m “misusing” the field name to denote whether to remove the comments, but first lets handle all the other field names
- Build an optional comment string to include before and after
- Depending on the length of the field name, either output just the icon and the date, or a proper inline field definition with the date including the
[ ]
- Back to removing the comments, then remove whatever comments are present. Note that this expression is greedy, so if you type something like
%% a comment%% some non comment %% another comment $$
it’ll happily gobble up all of that text. So keep comments at the end of the task!
- End the template by replacing the selected text with our modified alternative
How to use this template
Following the previous described workflow:
- Triple-click one tasks to select of that task
- Trigger the template, through a hotkey or other means, and select one of these options in the suggester:
- Cancel task
- Task in progress
- Complete task
- Complete task
- Clear the task (and remove any comments)
I can do all of those actions, one after the other, and change the following list of tasks:
- [ ] Just testing
- [ ] To be canceled
- [ ] To be marked as in progress
- [ ] To be completed
- [ ] Complete with icon
Into the following modified list:
- [ ] Just testing
- [-] To be canceled %% [canceled:: 2023-03-10] %%
- [/] To be marked as in progress %% [started:: 2023-03-10] %%
- [x] To be completed [completion:: 2023-03-10]
- [x] Complete with icon ✅ 2023-03-10
And if I apply the last choice of the menu on all of these (one after another):
- [ ] Just testing
- [ ] To be canceled
- [ ] To be marked as in progress
- [ ] To be completed [completion:: 2023-03-10]
- [ ] Complete with icon ✅ 2023-03-10
Notice since the last two don’t use comments, their field marking is not removed. This will also preserve any other tagging of the tasks like due or start dates, and so on.
How to query these fields
The middle variant displays for me as follows:

And if I use the following query:
```dataview
TASK
WHERE file.name = this.file.name
AND (canceled OR started)
```
I get this output:

Extending the actions
If you feel like it, you could keep on adding or modifying the lines in the newStatusDict
, so that this template could be your go-to way of changing your tasks.
Just add, change or modify the lines according to the templates given, and it should pick up on the changes the next time you trigger the template. In fact, I’m seriously considering changing to using this template myself (with some more action related to adding custom statuses for tasks which I use a lot in my personal vault)
Some final remarks and comments
- In the queries I’ve used
WHERE file.name = this.file.nam
to limit the test set. Modify/change/remove this according to your needs
- I’m using Minimal theme, and some custom formatting of fields, so your output might be a little different
- I’m also thinking about incorporating this into a multi using QuickAdd, where I’d also could add new custom tasks, but that’s a little beside this request
- I would love for this script not needing to pre-select the entire task, but I’m not sure how to reliable find the cursor position, and select the entire task programatically. If you know that, please let me know