Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Where does Mac OS X store Spotlight comments associated with a file? Is it stored as HFS+ file metadata, or is the information kept by the OS somewhere else?

share|improve this question
up vote 6 down vote accepted

The metadata is inside a hidden .Spotlight-V100 folder at the root of the indexed volume.

share|improve this answer

The values of the kMDItemFinderComment attributes that get stored in metadata store directories like /.Spotlight-V100/ depend on the extended attributes.

Finder also stores the Spotlight comments of all items in a folder in a .DS_Store file.

You can print Spotlight comments with mdls or xattr:

mdls -n kMDItemFinderComment test.txt

xattr -p file.txt | xxd -r -p | plutil -convert xml1 -o - - | ruby -rcgi -e 'puts CGI.unescapeHTML(<string>(.*)<\/string>/m)[0][0])'

If you use Finder to add a Spotlight comment for a file you don't have write permission to (like some application bundles in /Applications/), the comment won't be saved as an extended attribute, and it won't get picked up by Spotlight. You can open Finder as the superuser or use sudo xattr -w though.

If you delete a .DS_Store file from a folder and quit and reopen Finder, the Spotlight comments of all files in the folder disappear from Finder's information windows. If there are still extended attributes for the Spotlight comments, the comments are seen by Spotlight though.

If you use xattr to add a extended attribute, the comment gets picked up by Spotligt, but it won't be shown in Finder's information windows.

xattr -w comment file.txt

If you use AppleScript to change the comment attribute of a file, the comment is also saved in a .DS_Store file and shown in Finder.

osascript -e 'on run {f, c}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to c' -e end file.txt comment

(There is a warning like CFURLGetFSRef was passed this URL which has no scheme in 10.8 when a relative path is converted to an alias, but you can ignore it.)

share|improve this answer
Please provide a way to verify this. I was unable to do so. Setup: Create folders foo and foo/bar, use Automator to set Spotlight comment baz on foo/bar. Open foo in Finder, search for baz in it. This finds foo/bar. Then open Terminal, delete foo/.DS_Store (there's no foo/bar/.DS_Store). Relaunch Finder. Open foo in Finder, search for baz: Still finds foo/bar. – Daniel Beck Mar 11 '11 at 17:40
This works for me! Is there a way to write them? I've tried writing to the plist as well as an ascii-encoded hex string and neither sticks. I can write keywords that Spotlight finds using xattr -w Maybe I should write this as a question of its own... – beroe Aug 29 '13 at 17:50
@beroe I edited the answer. – user495470 Aug 30 '13 at 7:09

If you're trying to edit the spotlight comments on a file, you can see/modify them under the Get Info (command + I) window for the file.

share|improve this answer

You must log in to answer this question.

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