Trouble adding tag to task with OmniAutomation

Is anyone able to help with the use adding a tag?

The following works, and returns the tag:

var tag = flattenedTags.byName(“Response📨”);

But if I use the following line (amended Plugin of of-complete-await-reply.omnijs)


with the not found error of ‘Error: Function Task.addTag argument “tag” at index 0 requires a non-null value’

I’ve tried adding spaces, changed “” to ‘’ but I can not get it to work, a top level tag of “Test” does work.

Any ideas?

Thank you

Perhaps the use of tagNamed in the preamble to the plugin snippet assumes a slightly different context ?

.tagNamed is either a method of a Tag object, which lets you find its child tags by their name, or a method of the Database object, which lets you find a tag at the top level of nesting.

As you have already got a reference to the tag you want with:

const responseTag = flattenedTags.byName("Response📨");

You should be able to apply the .addTag method to that reference directly:

(() => {
    "use strict";

    const responseTag = flattenedTags.byName("Response📨");

    // etc etc ... defining dupTasks and dupTasks[0] somewhere ...
    // e.g. dupTasks = flattenedTasks; ...

1 Like

If you weren’t sure whether a tag existed or not, you could write something like this:

(() => {
    "use strict";

    // main :: IO ()
    const main = () =>

    // -------------------- OMNIFOCUS --------------------

    // tagsAddedByName :: String -> IO String
    const tagAddedByName = tagName =>
        task => {
                tagOrNull = flattenedTags.byName(tagName),
                [message, foundOrCreated] = (null !== tagOrNull) ? (
                    ["found", tagOrNull]
                ) : ["created", new Tag(tagName)];

            return Boolean(task) ? (
                // In OmniFocus:

                // and in JavaScript:
                `Tag: '${tagName}' ${message} and added to task: ${}`
            ) : "No task reference supplied.";

    // MAIN ---

    // Everything defined now ... ready to evaluate.
    return main();

Thank you, by using this method has fixed the issue.

1 Like