2

I see that this has been answered previously by Ken T., but I have a case where the code appears to work, and the call to setxattr() returns 0, but the item I want to modify does not change.

Specifically, I'm trying to change the metadata attribute kMDItemDisplayName, and my call looks like this (modeled after the sample posted by Ken T):

[Note: the "name" param below is an NSString *]

rc = setxattr([pathString cStringUsingEncoding:NSUTF8StringEncoding],
                 "kMDItemDisplayName",
                 [name cStringUsingEncoding:NSUTF8StringEncoding],
                 [name lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
                 0,
                 0);

Doing an mdls on the file in question shows that the kMDItemDisplayName attribute is present, but I can't get it to change to anything other than the actual file name (which I assume is the default behavior).

Am I misunderstanding something about how setxattr() is supposed to work?

Any help very much appreciated.

Oh, BTW, why am I trying to do this? It appears (from examining how Bare Bones' Yojimbo does things) that Spotlight uses the kMDItemDisplayName value to list files in the Spotlight search results menu in the finder, which is something I'd like to implement in my app.

Thanks!


Heyyyy... wait a minute...

From the command line, doing xattr -l shows that as far as xattr knows, there is an attribute called kMDItemDisplayName, and it is what I set it to be... However, mdls on the same file still shows the kMDItemDisplayName attribute as the file name.

Do I need to be asking about Launch Services instead of xattr stuff??


4

1 回答 1

3

好的。在四处寻找并阅读更多 Apple 文档后,我意识到我需要做些什么。我正在回答我自己的问题,希望这些信息可能对其他人有所帮助。

因为我必须编写自己的 mdimporter 来支持我的应用程序的文件格式,所以我想我会尝试在元数据导入时将 kMDItemDisplay 名称项添加到元数据存储中。

令我惊讶和高兴的是,它在第​​一次尝试时就奏效了!

因此,答案是,如果您想要覆盖或添加自定义 kMDItem* 类型,您可以在元数据导入时使用 Spotlight 导入器执行此操作。

希望有人觉得这有帮助!

于 2012-11-29T08:22:15.803 回答