Toggling Multiple Tags with Single Command

In case anyone else needs it, I hacked together an example that cycles through tag values, rather than tags themselves. I have very little experience with scripting so if anyone else has a better way to achieve this please let me know :slight_smile:

A GTD status cycle that cycles through next action, later action, waiting action and someday action. If the tag @actionStatus doesn’t exist it’ll create one and default to the start of the cycle (next action).

function TaskPaperContextScript(editor, options) {
    let outline = editor.outline
    let selection = editor.selection
	
    outline.groupUndoAndChanges(() => {
        editor.selection.selectedItems.forEach((item) => {
		if (item.getAttribute("data-actionStatus") === "next action"){
			item.setAttribute("data-actionStatus", "later action")
        } else if (item.getAttribute("data-actionStatus") === "later action"){
			item.setAttribute("data-actionStatus", "waiting action")
        } else if (item.getAttribute("data-actionStatus") === "waiting action"){
			item.setAttribute("data-actionStatus", "someday action")
		} else {
			item.setAttribute("data-actionStatus", "next action")
		}});
	})
	
	editor.moveSelectionToItems(selection)
}

Application("TaskPaper").documents[0].evaluate({
    script: TaskPaperContextScript.toString()
});
3 Likes