I'm trying to programmatically change the colour of tags in Apple Finder.
I can add tags using folder item.setTagNamesMBS, but there doesn't seem to be an equivalent to set the colours. So instead I am trying to edit the content of com.apple.finder.plist.
I can find the appropriate cfDictionaryMBS in the plist, but I don't seem to be able to change the content prior to saving. Here's the latter part of the routine...
Public Function updateTag(oldName as string, newName as string = "", colourNumber as integer) as boolean Dim cd As cfDictionaryMBS = get_CFDict_forTag(oldName) //returned from the array in plist If cd = Nil Then Return False //make it editable Dim cdm As CFMutableDictionaryMBS = cd.edit If newName = "" Then newName = oldName cdm.set(NewCFStringMBS("n"), NewCFStringMBS("newName") ) cdm.set(NewCFStringMBS("l"), NewCFNumberMBSInteger( colourNumber ) ) //commit?? //cd = cdm //this has modified the dictionary within the file //now need to write back the whole file I think - can't just update the one item Dim b As Boolean = cd_plist.writeToFile(fPlist, True) //this is working but the plist still has old values in it If b = False Then MsgBox "failed to write to plist" End If //return true if it worked Return b End Function
Basically I am unclear as to how to get the mutable dictionary back into the original dictionary (cd_plist) - which I have also made as mutable. Do I have to make all intermediate dictionaries in the hierarchy mutable too or is there something else I am missing?