I'm working on a project that involves reading and writing metadata from files. On a mac, by right clicking and selecting 'Get Info' on a file, you can view and edit certain bits of metadata.
I have found a way to upload tags (extremely useful tool found here). Now I need a way to change a file's "Comments" from the command line.
Is there any way to do that?
Thank you very much in advance!
You would use the global variable NSMetadataItemCommentKey
of NSMetadataItem
:
Swift:
let NSMetadataItemCommentKey: String
Objective-C:
NSString *const NSMetadataItemCommentKey;
↳ Foundation : NSMetadataItemCommentKey
Another ( quick ) way this might be done could be by calling Applescript
from bash
:
update_comment.sh
#!/bin/bash
filepth="$1"
updated="$2"
comment=$(mdls -r -nullMarker "" -n kMDItemFinderComment "$filepth")
printf "%s ( comment ): %s\n" "${filepth##*/}" "$comment"
printf "%s ( updated ): " "${filepth##*/}"
/usr/bin/osascript -e "set filepath to POSIX file \"$filepth\"" \
-e "set the_File to filepath as alias" \
-e "tell application \"Finder\" to set the comment of the_File to \"$updated\""
synopsis:
$ sh update_comment.sh /path/to/file "I'm the NEW comment"
Result:
file ( comment ): I'm a comment
file ( updated ): I'm the NEW comment
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With