Edit AllPages

** AEBuildAppleEvent()** is a Carbon function for creating an Apple Event, including parameters, in a single call (available in OS X 10.0 and above). The event’s direct parameter and other parameters can be included in the arguments to the call in a printf-like string format either as literals, or with substitution operators (think “%d”, except this uses “@” and “@@”).

AEBuildAppleEvent is a replacement for using a series of Apple Event Manager calls to create an event ( AECreateDesc, AECreateAppleEvent, etc.)

For an overview of the function, a bit of sample code, and some constants, see Apple Events Programming Guide “Creating and Sending Apple Events”. Constants are described fairly well in Appendix B.

For a detailed description of the function, including the paramsFmt string syntax, see “AEBuild, AEPrint and Friends” (keep reading to get past some forward references). The note describes how print descriptors of events sent by regular AppleScript by attaching gdb to Script Editor. This is a good way to get meaningful examples of the special string format.

For general AE-creation sample code (but not using AEBuildAppleEvent):

For the bulk of AE functions and constants, see (reference of last resort–constants are listed without order or definition).

** Context: ** As of OS X 10.4, Cocoa does not provide a mechanism to send individual Apple Events. You can either:

It is possible, but complicated, to pass arguments to the precompiled AppleScript from your code ( ).

This context section probably belongs some other page; I’m not sure where.

AEBuildAppleEvent is rather particular about the string. If you use AEPrint output as a guide (above), add corecions around the values. (see also ). The good news: the AEBuildError return actually tells you the character position in the string it has trouble with.

The easiest way to find AppleEventCode is to find the .scriptSuite file for the application. For example, to find out QuickTime’s playSelectionOnly command, go to ./ Simply open the file in your favorite text editor and search for what you want.