Today I tried to edit the metadata of a picture file. I used mdls to display them, then looked for a command to edit one. But I couldn't find any.

For vanilla metadata, like basic timestamps, touch is good enough. And for these things called "extended attributes" (quarantine, etc.), macOS gives you xattr -d.

But is there a CLI way to edit, say, kMDItemBitsPerSample or kMDItemFSName, or the key/value pairs used by Spotlight?

1 Answer 1


The Spotlight system collects a variety of types of metadata about files. Some kinds of metadata are what I'd call "superficial", and can be easily changed by changing the file properties; but some "deeper" ones depend on the contents of the file, and cannot be changed without significant changes to the file itself.

kMDItemFSName is an example of a "superficial" attribute -- it's just the filename, so renaming the file will change it. kMDItemBitsPerSample, on the other hand, is a property of the data in the file (it's the bit depth of an image or audio file). Changing kMDItemBitsPerSample would involve some sort of recoding of the image or audio file.

Mind you, there are some attributes that are in-between in superficiality. For example, mp3 files include metadata like the album name (kMDItemAlbum) and track number (kMDItemAudioTrackNumber) that are part of the file's contents, but can be edited (by some apps, like the old iTunes) without touching the audio content of the file.

  • You also can use xattr to modify some of them. Not sure what happens if you use it to change kMDItemFSName though
    – nohillside
    Oct 20, 2020 at 9:00
  • 1
    @nohillside I tried using xattr to set both kMDItemBitsPerSample and com.apple.metadata:kMDItemBitsPerSample on a .tiff file, but mdls continues to show the original (correct for the image data) value. (xattr -l does show the attributes I added.) Oct 20, 2020 at 23:44
  • In general, if you change a property of the file I don't think mdls going to reflect that until you use mdimport to import that specific file again to update the spotlight database. In this case I don't think those attributes are part of the extended attributes of the file ( I don't see them in my sample files).
    – Dad
    Aug 14, 2022 at 22:40

You must log in to answer this question.

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