I would like to me able to set (and get) a custom metadata attribute for any file.
What is the best way to do this?
Thanks
If you want to programmatically set the "Finder Comment" of a file (see @PurplePilot's answer), try this:
1) Create a regular xml plist file with your comments:
My Custom Comment
2) Convert the plist to the accepted binary format:
plutil -convert binary1 my_custom_comment.plist
3) Using xattr
, set the kMDItemFinderComment metadata:
xattr -wx "com.apple.metadata:kMDItemFinderComment" "`xxd -ps my_custom_comment.plist`" MyFile
You can see with xattr -l MyFile
that the comments are there and in the right binary format, but for some reason Finder doesn't show it (at least for me) in the Comments column.
Searching against the spotlight database with mdfind "My Custom Comment"
will return all the files with this comment.