I want to create a KM macro that will first check if the current line I have selected has any kind of tag attached to it, if yes, it will remove it, if not, it will add a tag @ask for me.
So given this:
Pressing the macro would do:
And given:
Macro would add the tag instantly:
I can’t quite figure out how to do the check whether the tag exists (ideally there is some applescript/jxa I can run that would return true or false).
And I also can’t find code to quickly add a tag. There is hotkey for removing tags thankfully.
I only have this macro for adding a tag to end but that is not ideal.
function TaskPaperContext(editor, options) {
let outline = editor.outline
let selection = editor.selection
let currentItem = selection.startItem
if (!currentItem) {
return
}
outline.groupUndoAndChanges(function() {
var removedTags = false;
for (let each of currentItem.attributeNames) {
if (each.startsWith("data-") && each != "data-type") {
currentItem.removeAttribute(each);
removedTags = true;
}
}
if (!removedTags) {
currentItem.setAttribute("data-ask", "");
}
});
editor.moveSelectionToItems(selection)
}
Application('TaskPaper').documents[0].evaluate({
script: TaskPaperContext.toString()
});