Create new extension association and icon in SnowLeopard

3

4

I was searching for the best way to add a new file extension type (.xyz) and associate an icon to all files of that kind in SnowLeopard.

Scakko

Posted 2011-02-16T09:35:27.477

Reputation: 133

Answers

5

It depends on whether you want a specific application to open these file types, or leave them unassociated.


If you want them to open with a specific application, you select that application in one of these files' Get Info dialog and check Always Open With in the selection dialog.

Now this file extension is associated with that application, but probably has a generic icon. The icon is the associated application's responsibility, so we need to change it.


Now you need to edit your application's bundle:

Right-click the application to handle these file extensions and select Show Package Contents. Navigate to Contents, and edit Info.plist. You might need Property List Editor, which is part of Apple's developer tools. If you're lucky, it's an XML format. Edit this file's CFBundleDocumentTypes and add the following for the extension .foo:

<key>CFBundleDocumentTypes</key>
<array>
    <!-- keep the other entries! -->
    <dict>
        <key>CFBundleTypeExtensions</key>
        <array>
            <string>foo</string>
        </array>
        <key>CFBundleTypeIconFile</key>
        <string>FooDocument</string>
        <key>CFBundleTypeName</key>
        <string>Foo Document</string>
        <key>CFBundleTypeRole</key>
        <string>Viewer</string>
    </dict>
</array>

Save the file.


For the icon, you need to create a file in AppName.app/Contents/Resources/ named FooDocument.icns. You can create icns files using Preview or specialized utilities.


You will need to repeat this every time you update the application.


If you don't want the files to open with a specific application, you can create a new "dummy" application bundle (it doesn't even need to be able to launch), where you place the icon and add the CFBundleDocumentTypes information from above.

Daniel Beck

Posted 2011-02-16T09:35:27.477

Reputation: 98 421

To get the changes to take effect, move the application to a different folder and back again, and relaunch it. This will update Launch Services. – Daniel Beck – 2011-02-16T10:12:05.730

A more elegant solution would be creating the dummy application and associating it with the file extension, but making it launch the real editor. – Daniel Beck – 2011-02-16T10:14:06.757

Yep, works. I'll add an explanation to my answer if you want. – Daniel Beck – 2011-02-16T10:29:19.350

I think i will stick with the dummy application because i have no need to associate file with apps. Thanks a lot for the info, Greatest. answer. ever.

What is the minimum requirements for a dummy application? may i build one only with the Info.plist and the FooDocument.icns? – Scakko – 2011-02-16T10:33:03.417

@Scakko I'm not sure. Safe bet is to launch Automator, select the Application template, and save. Then go crazy within that app bundle. Change the CFBundleTypeRole to None as a precaution, otherwise your empty application might get associated with the file type.

– Daniel Beck – 2011-02-16T10:44:53.250