11

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.

0

1 Answer 1

9
+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
3
  • The second link is for Carbon - do you know if this is supported in Cocoa?
    – Andrew
    Commented May 9, 2018 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
    Commented May 10, 2018 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. Commented Jul 9, 2019 at 14:29

You must log in to answer this question.

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