Is there a way to check if current line selected has a tag attached in code?


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.


Thank you for any help.


Here’s a script that will do that I think:

function TaskPaperContext(editor, options) {
	let outline = editor.outline
	let selection = editor.selection
	let currentItem = selection.startItem
	if (!currentItem) {
	outline.groupUndoAndChanges(function() {
		var removedTags = false;
		for (let each of currentItem.attributeNames) {
			if (each.startsWith("data-") && each != "data-type") {
				removedTags = true;
		if (!removedTags) {
			currentItem.setAttribute("data-ask", "");


  script: TaskPaperContext.toString()


Thank you :orange_heart: