Folderitem.SetTagNamesMBS with specific colour?

Hi,

I’d like to add tags to files/folders. Mac OS supports several tags for a given folderitem, each having a separate colour.

When I do this:

Var Tags() As String=Array(“Custom tag 1”,“Custom tag 2”)
Var Result As Integer=Item.SetTagNamesMBS(Tags)

This adds the tags; fine. But how do I tell that “Custom tag 1” would be, for instance, green and “Custom tag 2” would be orange?
(those tags may not already be known by the OS).

Well, you don’t define the color since the API for this only takes text.
Maybe the user can define such a tag before and it picks up the color for other files?

In at least two apps, I can add a tag with a specific colour (the Finder and Path Finder).
Using the Finder, I choose “Tags…” and start to type a value that doesn’t yet exist, in the text field. There’s the option to create the tag with that name and to choose the colour.

In Path Finder, under “Tags and ratings”, I can add tags and change the colour of the existing tags.

Perhaps I’m looking at the wrong place?

This would probably work; I’m still hoping to get how other apps can define the colours for each tag.
Maybe it’s not using the tags API for folderitems?

Thank you.

I tried it and it doesn’t work. I’ve defined a tag (“Uncertain”, with a yellow colour) and the code below just adds the tag with no colour.

Var f As new FolderItem(Path)
Var Tags() As String=Array(“Uncertain”)

Var i As Integer=f.SetTagNamesMBS(Tags)
Break

If the old way of adding chr(10) like the MBS documentation states is still valid, how does it work exactly?

Related (so not really off topic):
I fired AppleScript Editor,
Set recording mode
back to Finder
Create new folder,
Set tag to red
Back to AppleScript Editor
Stop recording

The red Tag does not appeared in the code.

Checked the AppleScript dictionaries for Finder and Standard Addition: tag is unknown…

Ventura.
FWIW.

You could always go and use NSAppleScriptMBS class to run an apple script to make the tag you need.

Thanks for your answers.
It looks like the Chr(10) trick does what I want, up to a certain point.
Hoping that won’t break soon (as it’s a backward compatibility feature).

I’ve used name + chr(10) + colorNo for some time now, seems to work OK though limited to only 8 colours (0-7).

1 Like

Thank you. I’m reassured to read it’s actually supported.