10

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?

3 Answers 3

9

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

7

The values of the kMDItemFinderComment attributes that get stored in metadata store directories like /.Spotlight-V100/ depend on the com.apple.metadata:kMDItemFinderComment 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 com.apple.metadata:kMDItemFinderComment file.txt | xxd -r -p | plutil -convert xml1 -o - - | ruby -rcgi -e 'puts CGI.unescapeHTML(STDIN.read.scan(/<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 com.apple.metadata:kMDItemFinderComment extended attribute, the comment gets picked up by Spotligt, but it won't be shown in Finder's information windows.

xattr -w com.apple.metadata:kMDItemFinderComment 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.)

3
  • 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, 2011 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 com.apple.metadata:_kMDItemUserTags Maybe I should write this as a question of its own...
    – beroe
    Aug 29, 2013 at 17:50
  • 1
    @beroe I edited the answer.
    – Lri
    Aug 30, 2013 at 7:09
0

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.

You must log in to answer this question.

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