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

Monitor AppleEvents an application sends and receives System
It is sometimes useful to monitor AppleEvents that certain applications are sending or receiving. You can monitor this in the Console for a certain application by opening a terminal window and typing:
 % setenv AEDebug 1
 % setenv AEDebugSend 1
 % setenv AEDebugReceives 1
Then you need to open the application from the same terminal, using this command:
 % open /Applications/Example/AppName.app &
The & launches the program in the background; for a GUI application this makes no difference to use, but it allows you to close the terminal window. Next, you should open the Console (in /Applications -> Utilities), where you can see any AppleEvents being sent or received by that application.
    •    
  • Currently 2.75 / 5
  You rated: 4 / 5 (4 votes cast)
 
[8,328 views]  

Monitor AppleEvents an application sends and receives | 8 comments | Create New Account
Click here to return to the 'Monitor AppleEvents an application sends and receives' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Monitor AppleEvents an application sends and receives
Authored by: kerbaugh on May 02, '03 05:12:34PM
Wow! This is a fantastic hint! There's an app, UIElementInspector, that can help with GUI scripting. However, it doesn't show the Apple Event like your hint. There is however an unfortunate side effect. If you execute a command, alias or script that uses osascript, it will fail and more than 2000 lines will be dumped into your terminal window. Apparently the logging is written to the Terminal window but I have no idea what all that junk is. Any ideas? Still, I've written a script to toggle logging on and off quickly so this anomaly isn't a problem and this is a great hint, thanks!

[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: bluehz on May 06, '03 11:47:33AM
I am trying to create a small shell script to toggle monitoring AE events off/on but I am having no luck. It tells me:

~/bin/AEmonitor: setenv: command not found
~/bin/AEmonitor: setenv: command not found
~/bin/AEmonitor: setenv: command not found

Can you not use setenv in a shell script?

Pardon the hardwrapped lines in the script - I have no idea why MacOSXHints is doing that to my stuff

#!/bin/sh
#Script to monitor AppleEvents
#
echo -e "Turn AppleEvent monitoring off/on?: \c"
read fname
if [ $fname = off ]; then
setenv AEDebug 0
setenv AEDebugSend 0
setenv AEDebugReceives 0
echo 
"========================================
===================="
echo "AppleEvents Monitoring Disabled"
echo 
"========================================
===================="
else
setenv AEDebug 1
setenv AEDebugSend 1
setenv AEDebugReceives 1
echo 
"========================================
===================="
echo "AppleEvents Monitoring Enabled"
echo 
"========================================
===================="
echo "Launch applications from the terminal using this syntax"
echo ""
echo "         open /Applications/Example/AppName.app &"
echo ""
echo "to monitor the AE for that application."
echo ""
echo 
"========================================
===================="
fi</code>


[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: tjfarrell on May 06, '03 08:54:38PM

Your script is a bourne (sh) shell script (indicated by the
#!/bin/sh on the first line).

The Bourne shell and other shells based on it (zsh, bash, ksh)
use a different way to set environment variables. "setenv" is
appropiate for tcsh and csh shells.

You should use something like the following in the script.


# Export all environment variables.
set -a
AEDebug=1
AEDebugSend=1
AEDebugReceives=1

---
--
T. Farrell



[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: bluehz on May 07, '03 08:02:47AM

Thx! I am still a learning Shell Scripter as you can tell - thats
very useful info. Unfortunately - even after changing the setenv
stuff - its not working as planned. I launch the script, answer
"on" to talk AEmonitoring on - then launch a known
AppleScript type app - open AppName & - but I get no output in
the terminal. Any ideas????



[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: bluehz on May 07, '03 08:04:12AM

Ooops - just noticed I need to be reading the Console for
output.... let me try that...



[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: kerbaugh on May 07, '03 11:22:30AM

Rather than asking the user what he wants to do, it might be easier to simply toggle from on to off or off to on, like so:

#!/bin/sh

if [ -z "$AEDebug" ]; then
export AEDebug=1 AEDebugSend=1 AEDebugReceives=1
else
unset AEDebug AEDebugSend AEDebugReceives
fi



[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: bluehz on May 08, '03 09:00:18AM

thx kerbaugh - I thought about that too. Was also thinking about
building it all into a single launch cmd of the sort you could do
something like:

AEmonitor <appname>

and have the script turn on monitoring, launch the app, and
display the consol (I watch my console in the terminal). Then
shutting it all down when exited.



[ Reply to This | # ]
Monitor AppleEvents an application sends and receives
Authored by: geoffsaulnier on Jun 07, '03 02:43:37PM

export varname = value

will surely only work in bash, ksh or zsh, right? Not in sh.


'course, most ppl use sh because you can virtually guarantee its presence on a system.

G.

---
___<br>
Geoff Saulnier - Mac, *NIX, perl, hack!!



[ Reply to This | # ]