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
Custom attribute names work for me:
$ xattr -w com.apple.metadata:MyAttribute gfdylvyieo a.txt
$ mdls -n MyAttribute a.txt
MyAttribute = "gfdylvyieo"
$ mdfind gfdylvyieo
/private/tmp/a.txt
$ mdfind 'MyAttribute=*'
/private/tmp/a.txt
xattr -wx
is not needed if the value is plain text:
xattr -w com.apple.metadata:kMDItemFinderComment aa file.txt
When you add a Spotlight comment from Finder, it is stored both as an extended attribute and in a .DS_Store file. If you just add an extended attribute, the Spotlight comment field appears blank in Finder, but the comment metadata is still indexed by Spotlight.