Applescript nested tag

I wish to insert a task with a specific nested tag. However, when I try to insert the tag, it defaults to the first level. My tag hierarchy is “Communicate : Waiting for…”. I am using this code snippet to insert the task:

property myWFTag : "Communicate : Waiting for..."
set theTag to make new tag with properties {name:myWFTag}
set theTask to make new inbox task with properties {name:theTaskTitle, note:theBody, primary tag:theTag, defer date:theStartDate, due date:theDueDate}

Does anyone know how to achieve scripting for a nested tag?

While far from an script guru try it without the parent tag, going straight to the “nested” one.

Thanks for the suggestion. I have tried that but “Waiting for…” just becomes a first level tag.

Perhaps this should work.

tell application "OmniFocus"
	tell default document
		set parentTag to make new tag with properties {name:"Communications"}
		set childTag to make new tag with properties {name:"Waiting For"} at end of tags of parentTag
	end tell
end tell
2 Likes

Hi @unlocked2412. Thanks for the comments.

Unfortunately, it did not work. I get a task but just with the “Communicate” tag and not “Communicate : Waiting for…”

I am sure there must be a way of doing this.

In full, it would be:

tell application "OmniFocus"
	tell default document
		set parentTag to make new tag with properties {name:"Communications"}
		set childTag to make new tag with properties {name:"Waiting For"} at end of tags of parentTag
        set theTask to make new inbox task with properties {name:"New Task", primary tag:childTag}
	end tell
end tell

Hi @unlocked2412. Thanks for your suggestion but it still does not work.

It creates a first level tag with the name “Communications:Waiting For…”. It does not add this to my existing “Waiting For…” tag.

Any other suggestions?

Based on your code, seemed like you were trying to create a nested tag and then add a new task with that specific tag.

If you have a parent tag named Communicate with child tag Waiting for..., this should work:

tell application "OmniFocus"
	tell default document
		set oTag to first flattened tag whose ¬
			(name of container = "Communicate") and (name = "Waiting for…")
		set oTask to make new inbox task with properties {name:"New Task", primary tag:oTag}
		return oTask
	end tell
end tell
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.