Do you need to do this programmatically or is manual/interactive OK? If manual is OK, here are some approaches:
Try using AppleScript Editor to record the target app.
Try using the techniques listed in Technical Note TN2124: Mac OS X Debugging Magic under Apple Events. For example, set the environment variable AEDebugReceives
to 1
and run the target app under that environment.