With UI Actions, you attach an AppleScript script to a
native Mac OS X application. From then on, the script will
be triggered automatically every time the user performs the
actions you specify in the target application. A UI Action
script can respond to all manner of user actions, such as
opening or closing a window, selecting a menu item, editing
a text field and many others.