Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Watch applications send and receive Apple Events System

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/.

    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[16,486 views]  

Watch applications send and receive Apple Events | 7 comments | Create New Account
Click here to return to the 'Watch applications send and receive Apple Events' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Monitoring ALL Apple events
Authored by: noworryz on Mar 21, '03 11:09:30AM

Doing what the hint suggests monitors events being sent and received by the Finder and the applications it launches. Monitoring stops when your log out. If you want to permanently turn on monitoring of all Apple events, whenever you log in, you can add AEDebugSends and AEDebugReceives to your ~/.MacOSX/environment.plist file, defining their values as 1.

You may have to create the both the directory and the file. Apple's QA1067 document tells you how.

--Glenn

[ Reply to This | # ]

Monitoring specific applications?
Authored by: gctuser on Mar 23, '03 01:01:22PM

Is it possible to set the environmnt variable in a way that restricts the console-output to specific applications?



[ Reply to This | # ]
Viewing events of a single application
Authored by: noworryz on Mar 23, '03 03:33:44PM

I've been asked if it is possible to restrict event viewing to a single application. You can do this by only launching one application with the environment variables set. For example, launch YourApp from the terminal as follows:


setenv AEDebugSends 1
setenv AEDebugReceives 1
open -a "YourApp"

--Glenn

[ Reply to This | # ]

Watch applications send and receive Apple Events
Authored by: Vocal Velocity on Dec 06, '04 01:49:48PM

how would this be done using the bash?
setenv is not available and export does not seem to like it either?



[ Reply to This | # ]
Watch applications send and receive Apple Events
Authored by: jimr on Jul 03, '06 01:45:45AM

put:
<pre>#Sets AEDebug in the terminal
export AEDebugSends = 1
export AEDebugReceives = 1
</pre>
in your login script (e.g. ~/.profile)
<br><br>
Though it seems that when .MAOSX/environment.plist exists, this is already there.

---
-----------------



[ Reply to This | # ]
Watch applications send and receive Apple Events
Authored by: Krioni on Apr 01, '13 01:09:39PM

On my MacBook, running Mac OS X 10.6.8, I had to use the following:

export AEDebugSends=1
export AEDebugReceives=1
open -a /Path/to/MyApp.app

(Note: no spaces around the equals sign). Also, any AppleScript commands needed to be run from within that Terminal window. What I did was create an AppleScript file with my test code, then save it to test-debug.scpt on the Desktop. Then, every time I wanted to send some debugging-log commands to my app, I would save the AppleScript file and run the following:

osascript ~/Desktop/test-debug.scpt

I'm actually doing this while trying to debug a bizarre FileMaker bug (?) where UI Scripting stops responding for about 7 seconds after you click a button that opens a new window. So many work-arounds have failed: "with timeout 0.1 seconds" ; "ignoring application responses" ; and more. Basically, when you tell System Events to click a button in the Manage Database window for FileMaker Pro Advanced, the GUI successfully clicks the specified button, the new window open, but then the GUI stops responding to any other Apple Events for about 7 seconds, returns a 'missing value' as the result of the click, and then resumes functioning as expected. Extremely frustrating, since it adds a completely unnecessary 7-second delay to every action that pops up a new window.



[ Reply to This | # ]
Apple Events Debugging: CAVEAT
Authored by: jimr on Jul 03, '06 02:33:04AM
This is an old hint, but still works.

At sometime I certainly installed the environment.plist file in my system, watched for Apple events, and promptly forgot about how it was done. Possibly, It was installed by an app called AE Monitor.

There are a few caveats.. first, it fills up your console.log with this debugging data as well, and several times I was able to use it, so I never got too worried about that...

Second, and this has been a major problem, as it took a very long time to come to a solution, it seems that AE debugging interferes with BBEdit's sftp logins. Though, every other application supporting the sftp protocol, and the command line seem to work just fine.

Now I had never seen this reported anywhere, and for some time I supposed it was a bug in either My Operating System (heavily tweaked), or in some other faulty configuration.

I searched EVERYWHERE for answers to the sftp problem. but have had no luck during the year or more that the problem has been following me around.

And, when I say following me, I mean, that I finally determined that BBEdit sftp was working just fine on any other account in my room and on *gasp* my machine...

It wasn't a super serious fault in my favorite text editor, especially as the excellent CYBERDUCK sftp client will work seamlessly with the text editor of choice...

It was just at the lower threshold of PITA... and so I let it slide for quite a long time, though, it was a bit frustrating.

So today, midst some system maintenance and upgrades , I decided to more carefully examine some of the differences between the normal login account and the spare account.

I noted that the AEDebugging was not global, and as I was looking for a non-global setting, I started to investigate in earnest.

Google soon led me to this hint as I was looking for a source of AE2000 debugger statements in my logs... so, here is one way to put them there..

And I surely found the ~/.MACOSX directory absent in the spare user account where things work perfectly, yet have none of my special customization ;-)

upon removal, and a restart... (Well.... the newest QT installer wanted that...)

The BBEdit sftp no longer fails upon activation and of course the logs will be free of AE property list declarations...
As you can read the hint, it's easy to turn back on... but it seems, you never know when some app, even the well written ones, will fail due to some customization.

Finally for the search engines... this BBEdit failure during sftp login is solved by disabling AEDebug

Though, as a developer, one may actually require AEDebugging and BBEdit sftp simultaneously ;-)

---
-----------------


[ Reply to This | # ]