Get tag from task with shortcuts

I wonder if someone knows of a way to get the name of an items tag with siri shortcuts?

tags property of a specific task is a list of tag objects, as you probably know. What would you expect to happen ? Getting the name of the first tag assigned to the task ?

In any case, I do not think that’s possible with Shortcuts. You would need to use JavaScript Automation to accomplish what you want.

I hopes for something as “primary tag” in the AppleScripts dictionary. But was afraid it wasn’t very likely to be possible. Maybe it’s time to learn JXA.

primary tag as in “the first one”, or as “the most important”?
There is a difference, and the latter is difficult to achieve.

You can parse out the results of the tags property and only return the 1st one. Deciding what is most important would be difficult to do without some way to look for it in the tags result

It is a curious omission that you can’t get the tag out of the Shortcuts magic variable for the task. You can get the tags with Omni Automation JavaScript as stated above. You can call Omni Automations from Shortcuts as previously discussed at Call x-callback-url from OmniJS?. The image below is an example.

The Find … Items action has been limited to only 1 item. For multiple items, you would need to be more creative.

There are several limitations with this approach:

  • From OmniFocus’ perspective, it is being asked to run potentially unsafe code. Consequently, it will ask for your confirmation each time. See for details. It is possible to disable the warning but I recommend against this as it would be unsafe.
  • Currently, I get an “OmniFocus does not handle “shortcuts-production” URLs” error but the script works fine once you dismiss the error. I don’t use the callbacks myself so I don’t know if the issue is new. It smells like a bug so I would recommend contacting support if you end up using it.
  • Bouncing back and forth between Shortcuts and OmniFocus with URLs is cumbersome and slow.

You may wish to consider using a different technology, My understanding is that the JXA you mentioned is a Mac-only system technology that uses the JavaScript Core language to access the same resources available as AppleScript. On iOS, Apple only provides Shortcuts, not JXA. Omni Automation is a cross-platform feature of the Omni apps that uses the same JavaScript Core language but exposes only resources that are specific to Omni’s apps.

You could move more or all of your logic into an Omni Automation action that lives within OmniFocus. OmniFocus actions can be triggered from Shortcuts using modifications to the URL method described above. If you instead start the automation from OmniFocus, it can hand off to Shortcuts as described at

1 Like

I don’t think this is the case. ‘Find Items’ (ie. actions/tasks) returns a Shortcuts Dictionary if there are multiple items matching the criteria (and of course if the ‘Limit’ parameter is set to more than 1).

I concur with your method for getting the tags of an item in Shortcuts.

Indeed. Perhaps I am wrong, but probably @Cleobis set ‘Limit’ parameter to ‘1’ in that Shortcuts example. That’s why he says “The Find … Items action has been limited to only 1 item”. Though, it is not possible to see it in the screenshot.

1 Like

Oh, I see it now. Limiting to 1 was intentional to keep the shortcut simple.

1 Like