Trying to use python to add and remove tags from tasks, tags get deleted instead


After pip install pyobjc, and creating a task called “test task” and a tag called “Test Tag”, I tried this:

from ScriptingBridge import SBApplication
from Foundation import NSURL
omniFocus = SBApplication.applicationWithURL_(
doc = omniFocus.documents()[0]
doc.inboxTasks().objectWithName_("test task").tags().removeObject_(doc.tags().objectWithName_("Test Tag"))

and nothing happened. If instead, I do this:

doc.inboxTasks().objectWithName_("test task").tags().removeObjectWithID_(doc.ta
gs().objectWithName_("Test Tag").id())

“Test Tag” is deleted from OmniFocus entirely, which was certainly a surprise.

In general manipulating task tags seems flaky and weird in ScriptingBridge, despite the fact that it seems to vaguely work in AppleScript. Is this just a bug or is there some subtlety I’m not seeing here?


Are you running in circles with one line of code? You find the object with the tag and remove the tag from the object all in the same line. What happens when you find the objects with the tag, set that result to an object/variable, and then remove the tags from the objects? IOW, use two lines of code.



I’ve tried dozens of variations of this, with temporary variables for various collections of things, different lookups by name, by ID, by index, etc; the result always appears to be the same.


OK. I just thought to ask what might have otherwise been obvious to others but not me. Thanks.