How to have Spotlight Comments actually get indexed by Spotlight

spotlight

I'm running the latest OS X (10.8.1). Yesterday I discovered the Spotlight Comments feature, so I went through many of my Applications and put useful comments in that field. For example, on Music Manager.app, I put the spotlight comment "google music", since it's Google Music's manager app and I would want that to appear in my search results.

It's been at least a day now and I still don't see it when I do a spotlight search for "google music". What am I doing wrong? How long does it take for Spotlight to realize applications have comments and index them?

Best Answer

The comments should normally show up in Spotlight results after you close an information window in Finder. You can tell Spotlight to reindex directories or files with mdimport, but it should do that automatically most of the time.

The Spotlight comments seem to be stored in both .DS_Store files and extended attributes. But if a file is owned by root, Finder doesn't write the comment to an extended attribute, and it won't be seen by Spotlight either.

If you use xattr to add the comments, they are picked up by Spotlight, but they aren't shown in Finder's information windows.

sudo touch test
sudo xattr -w com.apple.metadata:kMDItemFinderComment somecomment test

If you open Finder as root, they are saved in both extended attributes and .DS_Store files.

sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder