Toggling Multiple Tags with Single Command

@jessegrosjean — I love your script! Thank you!

Here is a minor variation that toggles between the following tags:

  • important
  • next
  • today
  • incubate
  • waiting
  • declined

function TaskPaperContextScript(editor, options) {
let outline = editor.outline
let selection = editor.selection

    outline.groupUndoAndChanges(() => {
        editor.selection.selectedItems.forEach((item) => {
			if (item.hasAttribute("data-important")) {
				item.removeAttribute("data-important")		
				item.setAttribute("data-next", "")
			} else if (item.hasAttribute("data-next")) {
				item.removeAttribute("data-next")
				item.setAttribute("data-today", "")
			} else if (item.hasAttribute("data-today")) {
				item.removeAttribute("data-today")
				item.setAttribute("data-incubate", "")
			} else if (item.hasAttribute("data-incubate")) {
				item.removeAttribute("data-incubate")
				item.setAttribute("data-waiting", "")
			} else if (item.hasAttribute("data-waiting")) {
				item.removeAttribute("data-waiting")
				item.setAttribute("data-declined", "")
			} else if (item.hasAttribute("data-declined")) {
				item.removeAttribute("data-declined")
			} else {
				item.setAttribute("data-important", "")
			}
        });
	})

	editor.moveSelectionToItems(selection)
}

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