I’m trying to use NSWorkspaceMBS.fileLabels to get the current label/tag set for Finder.
However, it returns the standard set of labels (None, Gray, Green, Purple, Blue, Yellow, Red, Orange) rather than the full set of user defined labels that you can see in Finder Preferences Tags.
Has anyone found this solution?
Please use FolderItem.TagNamesMBS function to get the user defined labels.
folderitem.SetTagNamesMBS function is also helpful to set them.
Or use CFURLMBS functions for kCFURLTagNamesKey key.
For NSURLMBS class, TagNames function does the same.
Or set/get resource value with NSURLTacNamesKey as key.
Thanks Christian
Those all seem to produce the tags for a specified file, whereas the Finder Preferences shows a list of all the tag names in on the machine. Is it possible to get that list?
The alternative for my app would be to iterate through all the files and recompile the list - which sounds lengthy.
Not sure how to get that list. Sorry.
well you can get them via applescript so there must be some way
looks like Finder has them stored somewhere
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set libPath to POSIX path of (path to library folder from user domain)
set libPath to current application's NSString's stringWithString:libPath
set prefsPath to libPath's stringByAppendingPathComponent:"SyncedPreferences/com.apple.finder.plist"
set theData to current application's NSData's dataWithContentsOfFile:prefsPath
set {theStuff, theError} to current application's NSPropertyListSerialization's propertyListWithData:theData options:0 format:(missing value) |error|:(reference)
if theStuff is missing value then error theError's localizedDescription() as text
set theTags to (theStuff's valueForKeyPath:"values.FinderTagDict.value.FinderTags.n") as list
Isn’t it cheating to read the preferences file from Apple?
Sounds like it’s just reading /Users/cs/Library/SyncedPreferences/com.apple.finder.plist file.
I’d say it’s fair game until you run into a permissions problem
https://developer.apple.com/documentation/appkit/nsworkspace/1527553-filelabelcolors?language=objc
https://developer.apple.com/documentation/appkit/nsworkspace/1533953-filelabels?language=objc
Norman - I think those produce the standard labels - per Christian’s NSWorkSpaceMBS. I’m trying to get the complete set, ie including the users custom labels.
com.apple.finder.plist does include the custom labels - but yes, that would create a permissions problem.