Add a specific tag to a list of OF3 tasks in Applescript

If I make a list of tasks like this:

set selectedTasks to every flattened task whose (flagged is true ) and (completed is false )

…How would I write a commend to add the tag “Next” to every task in that list that doesn’t already have that tag?


To find tag object:

set oTag to (first flattened tag of default document whose name is "Next")

To add a tag (also accepts a list of tag objects)

add oTag to (tags of item 1 of selectedTasks)

Just keep in mind that, if you are syncing with OF 2, only primary tag is going to be converted to a context. So, if a task has a tag named Today and you add tag ‘Next’ to it, I think only ‘Today’ is going to be converted to a context.