Re: Retrieve all available Finder tags on Monterey and later

Alex Zavatone

There's unfortunately no API in macOS to retrieve the tags that you have created yourself in the Finder.

The solution is to parse the ~/Library/SyncedPreferences/

This gets all Finder tags labels.

You can also select only the custom tags (ignore the system ones):

func customTagLabels() -> [String] {
    let url = URL(fileURLWithPath: "\(NSHomeDirectory())/Library/SyncedPreferences/")
    let keyPath = "values.FinderTagDict.value.FinderTags"
    if let d = try? Data(contentsOf: url) {
        if let plist = try? PropertyListSerialization.propertyList(from: d, options: [], format: nil),
            let pdict = plist as? NSDictionary,
            let ftags = pdict.value(forKeyPath: keyPath) as? [[AnyHashable: Any]]
            return ftags.flatMap { tag in
                if let n = tag["n"] as? String,
                    tag.values.count != 2
                    return n
                return nil
    return []

Text copied verbatum from StackOverflow.

Hope this helps.
Alex Zavatone

On Jan 13, 2023, at 8:31 AM, Steve Mills via <sjmills@...> wrote:

On Jan 12, 2023, at 12:37, Thomas Tempelmann <tempelmann@...> wrote:

I doubt it's Spotlight that stores them because they also work on vols where the Spotlight index is disabled.

Spotlight has to store them in order to find them, so they'd be stored there as well as where ever the file system puts them.

Steve Mills
Drummer, Mac geek

Join to automatically receive all group messages.