Watch applications send and receive Apple Events

Mar 21, '03 09:54:00AM

Contributed by: noworryz

Applications use Apple Events to communicate among themselves. If you've ever wondered what they're saying behind your back, just open the Terminal and type:

 % setenv AEDebugSends 1 
 % setenv AEDebugReceives 1 
 % /usr/bin/osascript -e 'quit application "Finder"'
 % /usr/bin/open -a "Finder"
Any applications you then open with the Finder will report the events they send and receive to the Console. Read the rest of the hint for an example of what you'd see...

For example, suppose you use the Finder to open Safari, then you double-click on a .webloc file on the desktop. In the Console, you will see the Finder send the "go to URL" event and Safari receive it:


AE2000 (474): Sending an event:
------oo start of event oo------
{ 1 } 'aevt':  GURL/GURL {
          return id: 31064065 (0x1da0001)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
  target:
    { 2 } 'psn ':  8 bytes {
      { 0x0, 0x2e0001 } (Safari)
    }
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' - 
        { 1 } 'TEXT':  21 bytes {
          "http://www.apple.com/"
        }
    }
}

------oo  end of event  oo------
AE2000 (477): Received an event:
------oo start of event oo------
{ 1 } 'aevt':  GURL/GURL {
          return id: 31064065 (0x1da0001)
     transaction id: 0 (0x0)
  interaction level: 112 (0x70)
     reply required: 0 (0x0)
  target:
    { 1 } 'psn ':  8 bytes {
      { 0x0, 0x2c0001 } (Finder)
    }
  optional attributes:
    < empty record >
  event data:
    { 1 } 'aevt':  - 1 items {
      key '----' - 
        { 1 } 'TEXT':  21 bytes {
          "http://www.apple.com/"
        }
    }
}

------oo  end of event  oo------

In the above, the Unix process IDs are in parentheses, in this case (474) and (477). The tag psn indicates the Process Serial Number, in hexadecimal. (When sending, the event target is the receiving process; when receiving, the target is the sending process.) The URL being opened is http://www.apple.com/.

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030318214645101