I am trying to write OM tags using xattr.
xattr -w com.apple.metadata:kMDItemOMUserTags tag1 a.rtf
This works fine for one tag, but how do I add two or more? I have tried various combinations of quotes, commas, \, etc. without success so far.
Help greatly appreciated.
Answer
OM tags (com.apple.metadata:kMDItemOMUserTags) as well as user defined tags (com.apple.metadata:_kMDItemUserTags) are stored in an extended attribute and its value is a binary property list that contains a single array of strings.
Example with the tag user (xxd’d and converted to a xml with plutil):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>user</string>
</array>
</plist>
Simply using xattr -w com.apple.metadata:kMDItemOMUserTags tag1 file
won’t create a properly defined OMUser or (Apple) User tag.
I recommend to use an “add tag” Python script like this one.
kMDItemOMUserTags seems to be outdated (or at least “difficult” to use) in macOS and are sometimes/often replaced with the _kMDItemUserTags even in OpenMeta apps.
Attribution
Source : Link , Question Author : Dave A , Answer Author : klanomath