Search code examples
macosinfo.plistuti

Associate custom file extension to my app


I am trying to associate a customized file extension let's say .abc to an application that I'm working on, so that when I double click on a file with that specific extension, my app launches.

A .abc file is just an archive file (.zip renamed to .abc) gathering several .xml files. When I load one of those .abc file with my app, the archive is extracted and the .xml files are parsed so I can set some values to some variables in my code.

If I understand correctly, there are two parts to this.

  • letting OS X know that .abc extension must be associated with my app
  • handling the file in my app once it's launched

For now I'm having issues with the first part. I've already read some stack overflow posts dealing with this subject (like here or here) but I can't understand how they come up with the content of the string value for the key <LSItemContentTypes> (I've tried abc but it doesn't work) and for the key <UTTypeIdentifier>.

So far, this is the code I've added to my info.plist file

<key>CFBundleDocumentTypes</key>
<array>
    <dict>
        <key>CFBundleTypeIconFile</key>
        <array>
            <string>myicon.icns</string>
        </array>
        <key>CFBundleTypeName</key>
        <string>My Custom Project File</string>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>LSHandlerRank</key>
        <string>Owner</string>
        <key>LSItemContentTypes</key>
        <array>
            <string>don't.know.what.to.put.here.abc</string>
        </array>
    </dict>
</array>

<key>UTExportedTypeDeclarations</key>
<array>
    <dict>
        <key>UTTypeConformsTo</key>
        <array>
            <string>public.data</string> <!--not sure about that value-->
        </array>
        <key>UTTypeDescription</key>
        <string>My Custom Project File</string>
        <key>UTTypeIdentifier</key>
        <string>don't.know.what.to.put.here.abc</string>
        <key>UTTypeTagSpecification</key>
        <dict>
            <key>public.filename-extension</key>
            <string>abc</string>
            <key>public.mime-type</key>
            <string>application/octet-stream</string> <!--not sure about that value-->
        </dict>
    </dict>
</array>

Also, is UTTypeConformsTo public.data ok in my case ? Since the customized file extension represents a archive containing xml files ?

If anyone could help me with this :)

Thanks


Solution

  • I found the solution to my problem, I just misread the documentation, since the key CFBundleTypeIconFile is a string and not an array of string (I got confused because I was following and iOS example using the key CFBundleTypeIconFiles which is an array)