Need to automate assigning a tag to a task

I want to assign a specific tag to the selected task by Keyboard Maestro, Shortcuts, Omni-Automation or AppleScript. I must be missing something —after 30 minutes of web searching, I found lots of things for manipulating and searching tags, but not one thing about assigning a tag.

My current Keyboard Maestro script for this just starts with in the task title field and tabs down to the tag field, but it’s not reliable, like many UI hacks. I’m looking for a more stable method.

Thanks,
Russell

FWIW, OmniAutomation Task class has the following instance function:

function addTag(tag: Tag, location: Task.TagInsertionLocation or null)

Adds a Tag to this task at the specified location relative to its other tags, or at the end if no location is specified. If the tag is already present, no change is made. The Database function moveTags can be used to control the ordering of tags within the task.

I found this on the Automators forum…

I’m just running it from Keyboard Maestro.

Best,
Russell

Using the ‘Toggle Tag’ plug-in works for me, because as a plug-in it allows you to assign a keyboard shortcut to each tag. You’ll have to find where to get that plug-in but I think it was from the Omni Automation website

I have an example here: https://github.com/psidnell/ofplugins/blob/master/repeatTag.omnifocusjs/Resources/repeat.js

Thanks. More direct than my Keyboard Maestro/AppleScript method.

Best,
Russell