I have a Mac OS X application that is also a protocol handler (just as, for example, Safari is a protocol handler for the HTTP and HTTPS protocols). So when a user clicks a
You can register a handler for each of the possible Apple Events you'll get on launch, and make note of which one you receive first.
kAEOpenApplication
.kAEOpenDocuments
(or
kAEPrintDocuments
).kAEGetURL
.There's also kAEOpenContents
, but I wasn't able to trigger it easily in my test app; it's probably worth supporting no matter what.
How Cocoa Applications Handle Apple Events documents all of this stuff.
There is one error in there, though; it says that AppleScript's "launch" will send kAEOpenApplication
. It won't, it'll send ascr/noop
(kASAppleScriptSuite
/kASLaunchEvent
, defined in ASRegistry.h
). I couldn't get the usual Cocoa event handler mechanism to trap this event, so you may need to do some more digging there.
One way you can check if the event is sent at launch is to register the event handlers in your application delegate's applicationWillFinishLaunching:
method; they should deliver by the time applicationDidFinishLaunching:
is invoked. With that method, you could potentially only check for kAEGetURL
.