0
votes

I have a document-based app with a custom file format, the UTIs and such set up as so:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>extension</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>Icon</string>
        <key>CFBundleTypeName</key>
        <string>Custom Document</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Default</string>
        <key>NSDocumentClass</key>
        <string>MyDocument</string>
    </dict>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeDescription</key>
        <string>Custom Document</string>
        <key>UTTypeIconFile</key>
        <string>Icon</string>
        <key>UTTypeIdentifier</key>
        <string>com.mycompany.appname</string>
        <key>UTTypeReferenceURL</key>
        <string></string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>com.apple.ostype</key>
            <string>XXXX</string>
            <key>public.filename-extension</key>
            <array>
                <string>extension</string>
            </array>
        </dict>
    </dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array/>

Which (I assume, based on what I have read) is the correct way to do it. Except, when I run mdls on any saved files, the UTI is listed as:

kMDItemContentType             = "com.apple.appname.document"

This is confusing, as I have literally copied and pasted entries from plists of example apps like, TextEdit, iSpend, and Sketch, all to no avail.

It is especially important that saved documents have the correct UTI because they need a custom QuickLook generator, which relies on the correct UTI.

Any help is greatly appreciated. Thank you in advance.

1
Have you created a custom extension for your UTIs?user557219

1 Answers

3
votes

Did you at one point do the following:

1) At some point, had com.apple.appname.document as your UTI type, and at that time, you created a custom document of your type in the file system.

3) You then changed the UTI settings in your app.

4) You are looking at the info for the file you created in step 1, and that file has not changed since it was created?

If so, try using the Terminal to touch the file in question to force a Spotlight re-index of it, then take another look.

Otherwise, it might also help to make sure you remove all extraneous copies of your app and then rebuild the Launch Services Database (you can use a utility I wrote to do it: Rebuild Launch Services Database.

In general, your Info.plist info is OK, though I would recommend the following:

  • In your UTExportedTypeDeclarations under the UTTypeTagSpecification, only specify an OSType (file type code) if you really know what you're doing. That means you of course aren't using a type like 'appe' that is all lowercase letters, as those are reserved for Apple. I know you were required to register creator codes (CFBundleSignatures) with Apple (I've done several myself), though I'm not sure about file types, and whether they're still doing that or not. If you specify some arbitrary file type code and don't have a feel for what actual codes have come into use over the last 30 years, you risk conflicting with existing defined types.

  • Change your document UTI type to be more specific to your type. Something like com.mycompany.appname.extension.

Then change change your document CFBundleDocumentTypes entry by removing the CFBundleTypeExtensions entry and adding a LSItemContentTypes like the following:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>LSItemContentTypes</key>
        <array>
              <string>com.mycompany.appname.extension</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>Icon</string>
        <key>CFBundleTypeName</key>
        <string>Custom Document</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Default</string>
        <key>NSDocumentClass</key>
        <string>MyDocument</string>
    </dict>
</array>

Then, finally check that any keys in your Info.plist aren't being overridden by localized versions in the InfoPlist.strings file, if you have one.