3

I'm building a macOS app which programmatically sets Finder tags for files using extended attributes similar to this answer for Swift 3: Set Finder label color. This works well.

However, I'd like to create a tag and make it available in the filesystem without having to add the tag to a particular file. For example, when the user clicks a button, I want to create a tag, similar to Finder - Preferences - Tags, where you can create a new tag by pressing the + button. You don't have to specify a file or folder.

I tried adding a new tag to _kMDItemUserTags of a dummy folder using the setResourceValue API. This creates the tag as expected. However, the dummy folder now shows up in the search for this tag, which is not nice. As soon as I remove the tag from the dummy folder again (and no other file or folder has this tag) the tag is gone from the list of available tags.

So, I wonder how is it possible to create a new tag in Swift and persist it without assigning it to a file?

Rckstr
  • 169
  • 7
  • Related: [List all tags in Terminal in Mavericks?](https://apple.stackexchange.com/questions/112388/list-all-tags-in-terminal-in-mavericks) – Willeke Jan 08 '19 at 10:41

1 Answers1

0

I did a bit of research on the subject recently when asked for tagging support being added to my "SDview" image viewer/organizer, and it seems that those tags do not have any storage, where you could add/persist them "for later use". The list of available tags is a dynamic construct built from Spotlight metadata aggregating tags already used. IOW if you want your tag to show up in the list of available tags - you have to have it assigned to something.

silverdr
  • 1,978
  • 2
  • 22
  • 27