UTI 和文件扩展名关联
在我的应用程序中,我想包含一个 QuickLook 插件,该插件可以读取其他应用程序也使用的非系统扩展(在本例中我们使用 RAR)。我在应用程序包的 Info.plist 中将扩展声明为 Exported UTI
,如下所示:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.archive</string>
<string>com.rarlab.rar-archive</string>
</array>
<key>UTTypeDescription</key>
<string>Custom RAR Archive</string>
<key>UTTypeIdentifier</key>
<string>com.my-company.rarx-archive</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>rarx</string>
</array>
</dict>
</dict>
</array>
我还适当地导入了 RAR UTI:
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.archive</string>
</array>
<key>UTTypeDescription</key>
<string>RAR Archive</string>
<key>UTTypeIconFile</key>
<string>RAR</string>
<key>UTTypeIdentifier</key>
<string>com.rarlab.rar-archive</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>rar</string>
<string>rarx</string>
</array>
</dict>
</dict>
</array>
在运行应用程序后,RARX 文件似乎永远不会与我的应用程序关联,尽管。为了检查关联,我使用了 mdls
,如下所示:
mdls -name kMDItemContentTypeTree "/Users/Me/.../A File.rarx"
>>> kMDItemContentTypeTree = (
"com.another-company.rarx-archive",
"public.data",
"public.item",
"public.archive"
)
为什么我的 UTI (com.my-company.rarx-archive
) 没有出现在该列表中?我相信这会导致我的 Quick Look 插件无法触发,因为这些文件与 com.another-company.rarx-archive
UTI 关联。我系统上的另一个应用程序是被使用的。使用调试输出运行 qlmanage
证实了这一点。
In my application, I wanted to include a QuickLook plugin that reads a non-system extension other applications also use (let's use RAR for this example). I declare the extension as an Exported UTI
in my app bundle's Info.plist like so:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.archive</string>
<string>com.rarlab.rar-archive</string>
</array>
<key>UTTypeDescription</key>
<string>Custom RAR Archive</string>
<key>UTTypeIdentifier</key>
<string>com.my-company.rarx-archive</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>rarx</string>
</array>
</dict>
</dict>
</array>
And I also appropriately import the RAR UTI:
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.archive</string>
</array>
<key>UTTypeDescription</key>
<string>RAR Archive</string>
<key>UTTypeIconFile</key>
<string>RAR</string>
<key>UTTypeIdentifier</key>
<string>com.rarlab.rar-archive</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>rar</string>
<string>rarx</string>
</array>
</dict>
</dict>
</array>
The RARX files never seem to get associated with my app after I run it, though. To check the association, I used mdls
like so:
mdls -name kMDItemContentTypeTree "/Users/Me/.../A File.rarx"
>>> kMDItemContentTypeTree = (
"com.another-company.rarx-archive",
"public.data",
"public.item",
"public.archive"
)
Why isn't my UTI (com.my-company.rarx-archive
) showing up in that list? I believe this is resulting in my Quick Look plugin not firing, as the files are associated with the com.another-company.rarx-archive
UTI. The other app on my system is what gets used instead. Running qlmanage
with debugging output bears this out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里的一个问题是您试图将同一扩展与两个不同的 UTI 关联,而启动服务无法处理这一点。您导入的
com.rarlab.rar-archive
声明是正确的,它将所有rar
类型的文件分配给com.rarlab.rar-archive
正如预期的那样。您不必要地声明了 Exported 声明,因为它尝试重新定义
rar
扩展名。您不想这样做,而只想利用 Imported 声明并在 QuickLook 扩展中使用 com.rarlab-rar-archive 来声明它可以处理的内容。只要其他应用程序没有声明 QuickLook 扩展,您就应该可以声明此配对并使其正常工作。但是,由于听起来其他应用程序已经有针对此特定 UTI 的 QuickLook 扩展,因此我认为您可能无法选择删除它。我的经验是,冲突的 QuickLook 扩展是先到先得的。
One problem here is that you are trying to associate the same extension with two different UTIs, which Launch Services can't handle. Your imported
com.rarlab.rar-archive
declaration is correct, and it assigns all files of typerar
tocom.rarlab.rar-archive
as would be expected.You have unnecessarily declared the Exported declaration, because it attempts to redefine the
rar
extension. Instead of doing that, you just want to make use of the Imported declaration and usecom.rarlab-rar-archive
in your QuickLook extension to declare what it can work on.As long as the other application doesn't declare a QuickLook extension, you should be fine declaring this pairing and having it work. However, since it sounds like the other app already has a QuickLook extension for this particular UTI, I think you may be stuck with the option of deleting it. My experience has been that conflicting QuickLook extensions are first-come, first-served.