AECaptureParser is a tool by Erik van Blokland, erik@letterror.com, which listens for AppleEvents and turns them into the Python code that will generate those events when executed. Lots more information is in the docstring in the code.