Is there a way to get Spotlight to search for xattr?

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.


Solution 1:

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