-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is the correct way to format keywords aka kMDItemKeywords? #83
Comments
Did you set the keywords on Cleanshot X with osxmetadata or were those set by the app or some other app? kMDItemKeywords should be a list of strings. The intended format for setting keywords is:
I'm not at my Mac but will verify this later tonight. For multi-value attributes, you need to set the value first (overwrite what's there) then append additional values. |
Thanks for looking. No I did not set that metadata myself, it's what comes out of the box with that particular app. I note that at least for Spotlight searches, it is parsed correctly by mds—even though the format might not be correct or recognized by osxmetadata. Thanks for the syntax for multiple keywords. I didn't know to use |
This is very odd. First, I verified that osxmetadata properly sets multiple keywords (
I've also verified that I have some apps installed that osxmetadata improperly displays the keywords for in the same manner as your example (a list of characters instead of a list of keywords). For example:
Every app that had keywords, did this. However, I have also verified that the metadata stored for these apps in
The type is clearly specified as an array of strings but for the apps, the value is stored as a single string with comma delimited keywords. $ python
Python 3.10.5 (main, Jul 17 2022, 07:22:36) [Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import CoreServices
>>> mditem = CoreServices.MDItemCreate(None, "/users/rhet/Dropbox/Code/osxmetadata/t.txt")
>>> value = CoreServices.MDItemCopyAttribute(mditem, "kMDItemKeywords")
>>> value
(
foo,
bar
)
>>> mditem = CoreServices.MDItemCreate(None, "/Applications/Yoink.app")
>>> value = CoreServices.MDItemCopyAttribute(mditem, "kMDItemKeywords")
>>> value
'drag,drop,move,copy,alias,file,shelf,utility,shelves,documents'
>>> And though it appears in Finder that Finder is showing the keywords, it's actually showing a single string for the Note that in this example (set by osxmetadata following the Apple documentation) that there are two keywords, separated by a comma and a space: And in this example of an app with the single string value, there is no space after the comma: However, when searching in Spotlight, both forms are correctly identified. For example, if I search for So, it must be that Spotlight works with both So what should osxmetadata do? I think the best approach is to continue to use an array of strings when setting keywords as the documentation states but to treat any value which is a single string and not a |
@all-contributors please add @luckman212 for bug |
I've put up a pull request to add @luckman212! 🎉 |
The mystery deepens. osxmetadata uses a private/undocumented Apple API ( |
Agree with this. It's definitely odd and not very reassuring, but it does work. |
Fixed in v1.2.1 |
Tested and working well! This is great 🚀 |
Last comment: osxmetadata/osxmetadata/mditem.py Line 155 in 719be3b
It might be nice to automatically trim the strings returned from this method, so we don't end up with keywords like This could be done with a simple list comprehension [x.strip() for x in str(value).split(",")] |
Thanks, good suggestion. Fixed in v1.2.2 |
@all-contributors add @luckman212 for code |
I've put up a pull request to add @luckman212! 🎉 |
I have some apps on my system that I get incorrect output from
osxmetadata --get kMDItemKeywords <path>
example, CleanShot X displays each character as an array element:
Are these supposed to be strings, arrays, or ... ? What's the correct way to write multiple tags to a file?
or
or
?
The text was updated successfully, but these errors were encountered: