How AppleEventBridge works

AppleEventBridge is a high-level Objective-C wrapper for the Carbon Apple Event Manager APIs.

AppleEventBridge builds upon the Carbon Apple Event Manager and Foundation APIs to provide:

The AppleEventBridge architecture consists of two layers, identified by the following class name prefixes:

The AEM API is largely intended for use by higher-level libraries, though may also be used by developers in cases where an application lacks terminology, or bugs within its terminology prevent its use by AEB.

The AEB layer consists of several AEBStatic... base classes and a code generator, aebglue, which creates static glue classes for individual applications. A number of AEBDynamic... base classes are also provided for use in constructing high-level bridges for scripting languages.

For example, the following AppleScript sets the size of the first character of every non-empty paragraph in every document of TextEdit to 24 pt:

  tell application id "com.apple.TextEdit"
     set size of character 1 of (every paragraph where it ≠ "\n") of every document to 24
  end tell

Here is the equivalent Objective-C code using AEM classes:

  AEMApplication *te = [[AEMApplication alloc] initWithBundleID: @"com.apple.TextEdit"];

  AEMQuery *ref = [[[[[[[AEMApp elements: 'docu']
                                property: 'ctxt']
                                elements: 'cpar'] byTest: [AEMIts notEquals: @"\n"]]
                                elements: 'cha '] at: 1]
                                property: 'ptsz'];

  AEMEvent *evt = [textedit eventWithEventClass: 'core' eventID: 'getd'];
  [evt setParameter: ref forKeyword: '----'];
  [evt setParameter: @24 forKeyword: 'data'];

  [evt send];

and using AEB glue classes:

  TEApplication *te = [TEApplication application];

  TESpecifier *ref = [[te.documents.text.paragraphs byTest: [TEIts notEquals: @"\n"]]
                                        .characters at: 1].size;

  [[[ref set] to: @24] send];