Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload Comments to File Metadata "Get Info" Mac Command Line

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!

like image 344
tsouchlarakis Avatar asked Mar 19 '17 17:03

tsouchlarakis


1 Answers

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
like image 66
l'L'l Avatar answered Nov 19 '22 02:11

l'L'l