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

How to map extra mouse buttons in only some apps System
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:
  • The mouse button that will be triggering the rule.
  • An Applescript-Number building block that is tied to the script and the result is limited to 0 or 1.
  • A Value Selector building block that turns on when the number 0 is fed into it.
  • An And building block.
  • A Keystrokes building block that is configured to press and release F9 when its input is ON.


These are tied together as seen in the above screenshot. So when the mouse button is clicked, its building block transitions to ON, and the script is run. If the script returns 0, the value selector turns ON. If the button is still pressed (since the script can run faster than one can let go of the button, the button will most certainly still be pressed), the And building block turns ON and causes the F9 keystroke to be sent.

If the script returns 1, the Value Select building block doesn't turn ON, and the F9 keystroke is not sent, instead the default use of the middle mouse button takes place for that application.

Here is a little more complex example I did that uses the same technique to assign the Exposť functionality to display the desktop (F11) to a mouse button for most applications, but then for my browsers, it assigns this button to do the key sequence to go back to the previous page (command-[).


The script is nearly identical to the one above, but it returns 1 if the frontmost application is one of my browsers.
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[14,884 views]  

How to map extra mouse buttons in only some apps | 3 comments | Create New Account
Click here to return to the 'How to map extra mouse buttons in only some apps' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
How to map extra mouse buttons in only some apps
Authored by: greed on Dec 23, '05 08:53:49AM
I'd look at hooking USB Overdrive up to my systems again; in fact, I'll probably do that anyway, now that I've got a Mac fast enough to be useful again.

[ Reply to This | # ]
How to map extra mouse buttons in only some apps
Authored by: ahbe on Dec 26, '05 05:34:06PM

This is a wonderful hint! I have a Logitech MX900 that never did work right with OS X. I have never been able to use the forward and back buttons in Safari. This is such a great solution. Now I have it setup so the back button goes back in Safari, but opens the Dashboard everywhere else. I'm a very happy man. Thank you.



[ Reply to This | # ]
How to map extra mouse buttons in only some apps
Authored by: sys0p on Dec 27, '05 02:53:07AM