6

I like to tag files with xattr, e.g. xattr -w user.foo bar myfile.

Is there a way that I can then use Spotlight to search for a given xattr key (or key-value pair)? For example, if I put foo or foo:bar in the Spotlight search bar, I'd like it to return myfile in the result list.

I realize you can do this by writing the com.apple.metadata:_kMDItemUserTags attribute - but this is not very portable, so I'm curious if this can be extended to all xattr tags.

5
+50

Based on this, yes but you are limited to using com.apple attributes. As for extending Spotlight to any xattrib tags, you could but you will need to develop an importer for Spotlight. There are plenty of metadata tags available, I would pick one to be used as a personal tag.

If committed to searching by custom xattrib, I would give up on Spotlight and use:

find . -xattrname foo
  • The second link is for Carbon - do you know if this is supported in Cocoa? – Andrew May 9 '18 at 19:56
  • I do not develop for macOS, but my understanding is Carbon uses pure C and Cocoa uses an objective-C API easily accessible to C or C++. The link definitely has objective-C examples. – Jason May 10 '18 at 16:14
  • I have developed a few Spotlight plug-ins and they can be written mostly in Objective-C. Some C is needed to set up the plug-in but this is provided by Xcode's project template. – Graham Miln Jul 9 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .