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

1k Views Asked by At

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".

2

There are 2 best solutions below

1
On BEST ANSWER

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.

2
On

As an intermediate between doing it by hand and doing it from Cocoa, there is an Automator action called "Set Application for Files".

I don't think there is a supported way to do it programmatically, but some people have figured out what Finder is doing: Adding a resource of type 'usro' that contains a full path to the application. See for example this discussion. Note: the Resource Manager is deprecated as of 10.8.