objective-cmacoscocoaopen-withdefault-programs

In Obj-C, how to programmatically set the default "open with" property of a file in Mac OS X


In creating some .mov files using Cocoa (Obj-C), I'd like to set them to be opened by default by a specific program, instead of the default. This should be a file level property, I do not wish to change the default program for all files with the same extension. This is to be done from Cocoa itself, as opposed to manually in "context menu">>"Get Info">>"Open With".


Solution

  • There's an undocumented function call that sets this:

    // undocumented function call
    
    extern OSStatus _LSSetStrongBindingForRef(const FSRef *inItemRef,
                                              FSRef *inAppRefOrNil);
    

    *If you use this in your application and submit it to the AppStore it will probably get rejected.