Changed spotlight comments not showing in Finder

I have a large number of files with comments set (with info on where they should be filed). Sometimes I need to reset the comments to blank.


From the Terminal I can run

xattr -d com.apple.metadata:kMDItemFinderComment name.ext


I can see that this has worked by using

xattr -p com.apple.metadata:kMDItemFinderComment name.ext


However, in the Finder window the comment is still there!


Am I changing the wrong attribute? Is the comment that appears in Finder stored elsewhere? If so, where?

iMac Line (2012 and Later)

Posted on Sep 17, 2019 8:57 AM

Reply

Similar questions

4 replies

Sep 18, 2019 3:22 AM in response to dave61

The script eliminates the need to use xattr. Let's take a file that has no com.apple.metadata:kMDItemFinderComment Spotlight metadata associated with it. You run this Zsh script on that file, adding a comment via the Finder. If you now run xattr -l on that file, it will have this metadata set on it, and you will see the comment string that you added through this script.


If you subsequently remove the comment from the file with this script, the com.apple.metadata:kMDItemFinderComment attribute remains, but is empty.


You can also verify that the Finder comment is set via:

mdls -name kMDItemFinderComment sample.txt


Sep 17, 2019 11:13 AM in response to dave61

All you are doing with xattr is manipulating Spotlight metadata. You will need to set the comment field as seen in a Finder Get Info via Finder itself. Here is a script that you can run in the Terminal that will either set or remove the current Finder comment field.


if the script name is cmt.zsh, you will need to first make it executable:

chmod +x ./cmt.zsh


Usage:

./cmt.zsh ~/Documents/somepath/file.txt ""  # clear the Finder comments on some file
./cmt.zsh ./file.txt "New comment string"   # adds a new Finder comment



Zsh script:

#!/bin/zsh

# Zsh script to clear, or set Finder Get Info comment field
# Adapted from: https://stackoverflow.com/questions/42889678/upload-comments-to-file-metadata-get-info-mac-command-line

# absolute file path
fpath="${1:a}"
# new comment string including ""
newcmt="$2"
# existing comment string or none
oldcmt=$(mdls -r -nullMarker "" -n kMDItemFinderComment "$fpath")
# get just the filename without its path
printf "%s (comment): %s\n" "${fpath:t}" "$oldcmt"
printf "%s (updated): " "${fpath:t}"

osascript -e "set filepath to (POSIX file \"$fpath\" as alias)" \
          -e "tell application \"Finder\" to set the comment of filepath to \"$newcmt\""
exit 0


You can run this Zsh script from within Bash. In Catalina, Zsh replaces Bash as the default Shell.


Terminal output with no pre-existent Finder comment:


and Get Info Comments from this file:


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Changed spotlight comments not showing in Finder

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.