Mac OS X sends Apple events to communicate with applications in certain common situations, such as when launching the application or asking it to open a list of documents. All programs are required to provide support for some AppleScript events (aka Apple Events). The required events are "Open Application", "Quit Application", "Open Documents", "Print Documents".
Adding full support for AppleScript is not a trivial task. As with many Carbon APIs, AppleScript is a combination of old and new. Legacy issues seem unavoidable. The best documentation of creating a scriptable application is ["Inside Macintosh: Interapplication Communication" @1993]. In particular "Resolving and Creating Object Specifier Records" seems to be required reading, as well as "Recording Apple Events". These chapters are well written but the examples are all in Pascal and the API calls that are demonstrated have long been deprecated.
The best place to start is the Apple's [Introduction to Apple Events Programming Guide]
Click here, to download the [AppleScript API].
There are several books on AppleScript but they're written for someone learning scripting and not for the developer.
You can run AppleScript from within a Carbon app using OSAExecute. [QA1026].
In order to debug any scriptable application or just investigate what kind of events an application sends debugging output can be turned on by typing the following lines in Terminal (and launching your app from there):
export AEDebug=1 export AEDebugSends=1 export AEDebugReceives=1 <launch application here>