FolderItem.TagNamesMBS documentation question

Hi,

The MBS documentation says this:

Please note that some tags may include chr(10) followed by a number to indicate which label color is used for compatibility to older OS X versions.

What is the new way of getting the colour of each tag?

Doing a quick search, I didn’t find any Apple API for getting the colors.

Thanks. I had searched a bit, too.

I’ve come to a working solution, albeit not documented and may change if Apple decides to (like quite anything else). I’m putting it here in case someone else has the same issue.

The idea is to parse the extended attribute that holds the tags.
First thing is to add a property to hold the result. I’ve chosen an array of pairs as the type (left holds the name while right contains the colour index). In this example, I use Tags() as pair.

Then read the extended attributes:

Var sh As new Shell
sh.Execute "xattr -p com.apple.metadata:_kMDItemUserTags "+Item.ShellPath

Tags=ParseBinaryTags(sh.Result)

And the function to parse:

Public Function ParseBinaryTags(Data As String) As Pair()
  Var Result() As Pair //Array of tags name and colour indexes
  
  If Data.LeftBytes(8)<>"bplist00" then raise new UnsupportedFormatException("Invalid string passed.",-50)
  
  Var Count As Integer=Data.MiddleBytes(8,1).AscByte-160 //How many tags are defined
  
  Var Offset As Integer=9+Count
  for i as Integer=1 to Count
    Var Length As Integer=Data.MiddleBytes(Offset,1).AscByte-82 //Length of next tag's name
    
    Offset=Offset+1
    Var TagName As String=Data.MiddleBytes(Offset,Length).DefineEncoding(Encodings.UTF8)
    
    Offset=Offset+Length
    
    if Data.MiddleBytes(Offset,1).AscByte<>10 then Raise new UnsupportedFormatException("Tags data is of unknown format.",-50)
    
    Offset=Offset+1
    
    Var ColourIndex As Integer=Data.MiddleBytes(Offset,1).ToInteger
    Result.Add TagName:ColourIndex
    Offset=Offset+1
  next
  
  Return Result
End Function