UTI's and File Extension associations
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.
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 type rar
to com.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 use com.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.
精彩评论