Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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.

share|improve this answer
    
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 Feb 16 '11 at 10:12
    
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 Feb 16 '11 at 10:14
    
Yep, works. I'll add an explanation to my answer if you want. –  Daniel Beck Feb 16 '11 at 10:29
    
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 Feb 16 '11 at 10:33
    
@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 Feb 16 '11 at 10:44
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.