views:

31

answers:

1

I'm creating an application for Mac OS X, and I wanted to know whether I've used UTIs properly in the application's .plist file:

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeIdentifier</key>
        <string>com.petroules.silverlock.database</string>
        <key>UTTypeDescription</key>
        <string>Silverlock Database File</string>
        <key>UTTypeIconFile</key>
        <string>app.icns</string>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string>
        </array>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>com.apple.ostype</key>
            <string>SDBX</string>
            <key>public.filename-extension</key>
            <array>
                <string>sdbx</string>
            </array>
            <key>public.mime-type</key>
            <string>application/octet-stream</string>
        </dict>
    </dict>
</array>

This code appears to work, although double-clicking a .sdbx file in Finder doesn't cause my application to open the file itself... but that might just be my code (something I'll look into later).

Also, the format of my file type is encrypted content encoded in base-64... is application/octet-stream the best MIME type to use for that or is there something else I should use, and could I possibly run into compatibility issues anywhere in the spectrum by using a less common MIME type?

Also, I included the following code:

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>sdbx</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>app.icns</string>
        <key>CFBundleTypeName</key>
        <string>com.petroules.silverlock.database</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>com.petroules.silverlock.database</string>
        </array>
        <key>LSHandlerRank</key>
        <string>Owner</string>
    </dict>
</array>

Should I include this at all because I have the UTI code above? Is this necessary? What are the differences between the two? I wasn't really able to ascertain that from the documentation. Thanks :)

+1  A: 

To find out whether this or your code is at fault, quit your app before double-clicking on the file. If this launches your app but doesn't open the file, then your Info.plist is fine and your problem is in -[[NSApp delegate] application:openFile:]. If the app doesn't launch at all, you can be sure that your Info.plist isn't correct as far as Launch Services is concerned.

You do need both the UTExportedTypeDeclarations and CFBundleDocumentTypes stanzas. The first one tells Launch Services that your custom UTI exists. The second tells it that your app is an editor for that file type.

Graham Lee
I should have mentioned it's a Qt-based app, so `[[NSApp delegate] application:openFile:]` doesn't apply... I'll have to check my code tomorrow. Thanks for the information regarding the plist file and UTIs.
Jake Petroules
See http://stackoverflow.com/questions/3451280/opening-files-from-finder-with-a-qt-based-application regarding opening files in Qt applications when they are double clicked in Finder.
Jake Petroules

related questions