views:

20

answers:

1

In a Document-based Cocoa application, handled file extensions are listed in the application's Info.plist file.

The application I'm building will require a loadable bundle for each type of file it opens. As such, I'd like the presence of bundles to modify the way my application registers itself as handling certain file types.

As an example, if the HTML.bundle is installed, my application should allow HTML documents to be opened, but if the bundle is absent then it should not.

Does it have to be an application-level setting, or can it be distributed through the installed bundles for the application?

I'm referring to "Document Types" in a Document Based application's Info.plist.

+1  A: 

You should rewrite the Info.plist file from within the application:

if (bundle_installed(@"HTML.bundle")) {
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:PATH_TO_PLIST];

    /* add/remove things to/from dict here */

    [dict writeToFile:PATH_TO_PLIST atomically:YES]; // atomically is important! Must be YES!!
}

This is very easy to implement, but however, your app must be restarted in order the make fulfill the changes.


You should add a back-up Info.plist into the Resources directory in the case something goes wrong.

Time Machine
Thank you :) I can deal with an application restart. I'm about to make a start on this now. We'll se how I go.
d11wtq
You'd need to be running as admin for this to work too (on most computers) making it rather icky
Mike Abdullah