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?


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 '20 at 9:00
  • @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.) – Gordon Davisson Oct 20 '20 at 23:44

You must log in to answer this question.

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