Creating apple shortcut to add tag to selected task

I’m writing a shortcut to enable me to generate a list of tasks with a particular tag, select some items from the list, and then tag them with ’today.’ I’m struggling with the Javascript. Does anyone know what the right script would be? I also want to do the opposite with another script (i.e. remove that tag ’today’ from the selected task). I’ve tried it with an omniautomation plugin (the ‘toggle tag’ from ‘generate toggle tag plugin’), but to no avail. Thanks for your help.

Post what you have (the actual Shortcut). The Omni Automation should just add a tag?

The answer really depends on what‘s inside Repeat Item, if the tag you want to apply has a unique name or not and if you want to reduce the amount of scripting to a minimum. That‘s why the Apple Shortcut and a few answers would help.

Thanks Logan. Here’s the shortcut:

Tag item from list

To answer your other question, the tag is ‘personal today’ - it will typically already be used for another task, but on occasion, all the items with that tag will have been completed when the shortcut is run so that it will be unique.

This should be the simplest code (even without error handling).
It takes the primary key from a selected object and passes it to a Omni Automation Script. The script then looks for the existing tag (maybe you have to rename), gets the action (task) by using the primary key and then adds the tag to the action.

1 Like

With unique I meant if there‘s only a single tag with that name. When you look for e.g. a tag by name it takes the first one it finds with the specified name. If there would be multiple tags with the same name (possible by using nesting), we‘d have to use its key to get a reference to it as well. If there‘s only one tag with that name, then the name is sufficient.

1 Like

Sorry, I just forgot. For testing purposes I reduced the maximum amount of actions displayed to just 3 instead of what you had set to 100. You may have to set that back to 100 again.

1 Like

Thank you! That’s so helpful. Did you learn through the omniautomation page (How to get going with javascript and Omnifocus? - #3 by draft8) or shine where else?

1 Like

Went through the Omni Automation course, but learned the most implementing plugins and Apple Shortcuts I and others in the forums needed. The real use cases advanced me the most.

1 Like

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