This article is from the Mac Programming FAQ, by Jon Watte email@example.com with numerous contributions by others.
There are four events your application really must implement if you
want to sell it: the kCoreEventClass class, kAEOpenApplication,
kAEQuitApplication, kAEOpenDocuments and kAEPrintDocuments events IDs.
When you support these events (or any AppleEvents) you will not get
startup info through GetAppParams() anymore, unless you run under System
6 of course. The kAEOpenApplication event will be sent to you when the
user double-clicks your app and it's not started yet. When receiving it,
you can put up a new untitled window.
kAEOpenDocuments is sent when the user double-clicks your apps documents.
Note that if the first AppleEvent you receive is a kAEOpenDocuments
event, the user started your app by double-clicking its documents.
kAEPrintDocuments is sent when the user selects your documents and
chooses "Print" in the Finder menu. If this is the first AppleEvent you
receive, you should print the documents and then quit the application
again; if you received a kAEOpenApplication or kAEOpenDocuments event
before this, you should just print the documents and close them when
kAEQuitApplication is sent to you when the user chooses "Shutdown" or
"Restart" from the Apple Menu. You should ask the user whether he wants
to save any unsaved changed documents, and then quit unless the user
Interestingly enough, you can use these four AppleEvents to send even to
non-AE-aware applications, and the system will translate these events
into fake menu selections for you.
A good way of shutting down the Finder is to send it a Quit AppleEvent.
You should send a Quit AppleEvent to File Sharing Extension before you
shut down the Finder, though; the FSE is found by looking for a process
with the creator 'hhgg'.