I use a multi-button mouse, and I wanted to put some of the exta buttons to good use. My initial thought was to assgn the middle mouse button to Exposé's All Windows functionality (usually assigned to the F9 key) in the Dashboard & Exposé System Preferences panel. However, I use Apple's X11, Terminal, and several other applications that have good uses for the middle mouse button.
So what I really wanted was a way to assign the middle mouse button to F9 on most applications and leave it the default on some others. ControllerMate allows you to assign a rule to specific applications or all applications, but they don't have the built-in functionality to exclude applications from a specific rule.
My solution to this minor dilemma was to create a ControllerMate rule that calls an AppleScript that returns a value of 1 or 0. If the script returns a 1, then the default use of the middle mouse button should be allowed (i.e. don't send F9). If the script returns a 0, then F9 should be sent.
The script is as follows:
on run
tell application "System Events"
set myApp to name of first application process ¬
where frontmost is true
--- Uncomment the next two lines to see the name of the frontmost
--- application; it is written to the system log.
---do shell script ¬
---"logger -t clickscript "Application was '" & myApp & "'.""
if myApp is "x11" or myApp is "Terminal" then
return 1
end if
return 0
end tell
end run
The ControllerMate rule contains the following building blocks:


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