In general, these are handled through Apple Events. Specifically, your application will receive an open document event. How you would handle it depends on what type of application you are writing.
If you're writing a document-based app, this is easy: the document controller receives an openDocumentWithContentsOfURL:display:error:
message (or openDocumentWithContentsOfFile:display:
for pre-Tiger systems), and will handle this accordingly.
For Cocoa apps that aren't document based, the application delegate will be sent an application:openFiles:
message. If the delegate doesn't respond to that, it will try sending other messages until the delegate responds to one (openTempFile:
, openFiles:
, and openFile:
, in that order).
Here's the documentation for handling Open Apple Events in Cocoa.
For Carbon apps, I can't really remember the details (been a while since I've written Carbon code), but if I recall correctly, you would install an Apple Event handler for kAEOpenDocuments
events with AEInstallEventHandler()
. See the documentation for more details.