问题描述
我看到Ken T.先前已经回答了这个问题,但是我发现代码似乎可以正常工作,并且对setxattr()的调用返回0,但是我要修改的项目没有改变. /p>
具体来说,我正在尝试更改元数据属性kMDItemDisplayName,而我的调用如下所示(根据Ken T发布的示例进行建模):
[注意:下面的名称"参数是NSString *]
rc = setxattr([pathString cStringUsingEncoding:NSUTF8StringEncoding],
"kMDItemDisplayName",
[name cStringUsingEncoding:NSUTF8StringEncoding],
[name lengthOfBytesUsingEncoding:NSUTF8StringEncoding],
0,
0);
在有问题的文件上执行mdls显示存在kMDItemDisplayName属性,但是我无法将其更改为除实际文件名(我认为是默认行为)以外的任何内容.
我是否误解了setxattr()应该如何工作?
非常感谢任何帮助.
哦,顺便说一句,为什么我要这样做呢?看来(通过检查Bare Bones的Yojimbo的工作方式),Spotlight使用kMDItemDisplayName值在查找器的Spotlight搜索结果菜单中列出文件,这是我想在我的应用程序中实现的.
谢谢!
嘿...等等...
从命令行执行xattr -l显示,据xattr所知,有一个名为kMDItemDisplayName的属性,这是我将其设置为....但是,同一文件上的mdls仍显示kMDItemDisplayName属性作为文件名.
我需要询问启动服务而不是xattr的东西吗?
确定.在搜寻了更多的内容并阅读了更多的Apple文档之后,我意识到我需要做的事情.我正在回答自己的问题,希望此信息可能对其他人有所帮助.
因为我必须编写自己的mdimporter来支持我的应用程序的文件格式,所以我认为我想尝试在元数据导入时将kMDItemDisplay名称项添加到元数据存储中.
令我惊讶和高兴的是,它在第一次尝试时就奏效了!
因此,答案是,如果要覆盖或添加自定义kMDItem *类型,请在使用元数据导入时使用Spotlight导入器进行.
希望有人发现这有帮助!
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??
OK. After hunting around a bit more and reading more Apple documentation I realized what I need to do. I'm answering my own question in the hope that this information may be of some assistance to someone else down the line.
Because I had to write my own mdimporter to support my app's file format, I thought I'd try adding the kMDItemDisplay name item to the metadata store at metadata import time.
To my amazement and delight, it worked on the first try!
So, the answer is, if you want to overwrite or add custom kMDItem* types, you do so at metadata import time, using a Spotlight importer.
Hope that someone finds this helpful!
这篇关于将Spotlight元数据写入OS X(特别是kMDItemDisplayName)上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!