From PreForm Assistive Technologies:
UI Actions brings "universal attachability" to AppleScript. Write a UI Action script and attach it to any standard native Mac OS X application. UI Actions automatically runs the script whenever you perform specified user actions in the target application. You select the user actions that trigger a UI Action script, including choosing a menu item, choosing a tab or clicking a button that changes a value in the user interface. UI Actions is similar to Apple's Folder Actions and Digital Hub Actions scripting additions, because it lets you respond and control what happens when a user does something with the computer. But it is universal, because UI Action scripts can respond to almost anything a user does in almost any application.