What is the command line to retrieve and write macOS file info "Description" field?
For the command line to get "Comments" field, I use this AppleScript command:
osascript -e 'on run {f, c}' -e 'tell app "Finder" to set comment of (POSIX file f as alias) to c' -e end "grace.mov" "hello world"
The files originate on an iphone where I add comments to photos and videos. When I send these to my Mac, the only way to view them is to do a Get Info and view the "Description" field. The Comments field is empty. Ideally I would like to copy what is in the Description field to the Comments field so they are visible in List view.
I've tried the commands mdls, xattr, exiftool, sips, identify to figure out which can list the Description.
On iCloud, this field is called "Caption" (viewed under the Info for the image).
The Finder doesn't exist on iOS devices, so its comments, which are a mixture of its .DSStore
file, the com.apple.metadata:kMDItemFinderComment
extended attribute (a binary property list), and Spotlight kMDItemFinderComment
metadata, wouldn't apply.
If they are something like macOS Photos captions, those would be Spotlight kMDItemDescription
, and/or Exif Description
metadata. You can copy Spotlight's kMDItemDescription
metadata, just be aware that if you are wanting to set an extended attribute via xattr
, the comment synchronization between the Finder, extended attributes, and Spotlight isn't very reliable.
One approach would be to get the Spotlight metadata and then tell Finder to set its comment, for example:
set theFile to (choose file)
set caption to (do shell script "/usr/bin/mdls -name kMDItemDescription -raw " & quoted form of POSIX path of theFile)
if caption is not in {"", "(null)"} then
tell application "Finder"
set existing to comment of theFile
set comment of theFile to existing & return & caption -- append
# set comment of theFile to caption -- overwrite
end tell
else -- no value
beep -- or whatever
end if