0

I found the command "mdls" which will show the metadata but I can't see how to delete it.

I want to get rid of the comments "kMDItemFinderComment", "kMDItemWhereFroms" from my files.

Is there a way to do this?

Jay
  • 6,572
  • 3
  • 37
  • 65
Mint
  • 14,388
  • 30
  • 76
  • 108

3 Answers3

5

I think you're looking for the xattr command, available in Terminal:

xattr -pr com.apple.metadata:kMDItemFinderComment /

that will print all the finder comments for all files on your boot volume. To delete, use the -d switch:

xattr -dr com.apple.metadata:kMDItemFinderComment /

You should test this out on a single file before running it in bulk.

usage: xattr [-l] [-r] [-v] [-x] file [file ...]
       xattr -p [-l] [-r] [-v] [-x] attr_name file [file ...]
       xattr -w [-r] [-v] [-x] attr_name attr_value file [file ...]
       xattr -d [-r] [-v] attr_name file [file ...]

The first form lists the names of all xattrs on the given file(s).
The second form (-p) prints the value of the xattr attr_name.
The third form (-w) sets the value of the xattr attr_name to the string attr_value.
The fourth form (-d) deletes the xattr attr_name.

options:
  -h: print this help
  -r: act recursively
  -l: print long format (attr_name: attr_value and hex output has offsets and
      ascii representation)
  -v: also print filename (automatic with -r and with multiple files)
  -x: attr_value is represented as a hex string for input and output
Jeff Paquette
  • 7,089
  • 2
  • 31
  • 40
  • Oh wow, there is a way, didn’t think it was possible, thank you! Also, where did you get that MAN info? I tried to look for it before “man xattr” but all I get is "No manual entry for xattr" – Mint Dec 18 '09 at 07:41
  • I would click on the tick, to accept this solution, but it keeps coming up with an error, so I guess you will have to wait 3 more days before getting the bounty :) – Mint Dec 18 '09 at 09:48
  • That's not a man page, that's just xattr --help. I don't have a manpage for it either (snow leopard). That's a bummer about the bounty, if I understand correctly I'll only get half the bounty if time expires. Is there a support email for SO? – Jeff Paquette Dec 18 '09 at 12:52
  • Oh ok, awesome, thanks. Looks like the tick worked today. Enjoy your bounty ) – Mint Dec 18 '09 at 21:12
2

You can do this by:

xattr -d com.apple.metadata:kMDItemFinderComment <file>
xattr -d com.apple.metadata:kMDItemWhereFroms <file>

Seems to work for me.

Alok Singhal
  • 93,253
  • 21
  • 125
  • 158
0

The Spotlight comments are also stored in .DS_Store files. If you try adding a comment in Finder's information window and running xattr -d com.apple.metadata:kMDItemFinderComment, the comment will still be shown in Finder, but not by mdls -n kMDItemFinderComment. This would delete both of them:

find . -name .DS_Store -delete
xattr -dr com.apple.metadata:kMDItemFinderComment .
Lri
  • 26,768
  • 8
  • 84
  • 82
  • I think that when you miss erasing the .DS_Store comment, then eventually spotlight will pick it up again, likely when another comment is added to a file in the same folder. – Tom Andersen Oct 23 '12 at 14:19