3

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

apalopohapa
  • 185
  • 3
  • 11
  • 1
    Are you looking to create a custom file extension? And is it to be opened by your application, or another application? – l'L'l Jan 19 '14 at 07:30
  • @I'L'I, it sounds to me like he does not want a custom file extension, but probably wants to know how Get Info / Open With is implemented. – JWWalker Jan 19 '14 at 07:39
  • Added to the post that the file type is .mov. They get opened by default by QuickTime, but the files I'm creating are to be opened by another program instead (when double-clicked by the user). – apalopohapa Jan 19 '14 at 07:42
  • Under the sandbox paradigm, developing an application to influence another application doesn't sound like a good idea. – El Tomato Jan 19 '14 at 09:45

2 Answers2

5

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.

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • I can confirm this works in OS X 10.9 and 10.8. Thank you. The AppStore is not an issue, this is only for internal use. – apalopohapa Jan 20 '14 at 03:10
1

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.

JWWalker
  • 22,385
  • 6
  • 55
  • 76
  • That's interesting information about the 'usro' resource. - As far as I can see it, the 64-bit slice of the Carbon framework still contains the Resource Manager functions. (And the Finder is also 64-bit, so there must be *some* way to do it programmatically.) – Martin R Jan 19 '14 at 09:02
  • Yeah, the Resource Manager works under 64-bit. My understanding is that it's deprecated mostly as a way to say, "You really shouldn't be using old-style resources for new stuff." – Wevah Jan 19 '14 at 09:05