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

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top