Swap left/right click on OS X via terminal

3

1

I'm looking for a way to swap the left/right button on my mouse (left/right handed person) via the Terminal.

Currently every time I want to switch this I need to go to System Preferences » Mouse » Change the option for Secondary click. It would be much easier to just run a quick command in the terminal.

I've seen things like this: defaults write GlobalPreferences com.apple.mouse.scaling -1

tl;dr: Is there a way to do this sort of command (above) for the mouse's secondary click via the terminal?

My OS is 10.7.5.

iDev247

Posted 2012-11-16T21:14:30.127

Reputation: 267

Just a question. Why do you need to constantly switch? I'm just interested. Is the computer is being used bu multiple people or something? – Josiah – 2012-11-16T23:50:01.900

Answers

5

The relevant command is:

defaults -currentHost write .GlobalPreferences com.apple.mouse.swapLeftRightButton -bool true

(or "false" to set it back to normal.) However, I don't know of a way to get the setting to take effect without logging out & back in, which is generally more trouble than using System Preferences to make the change.

Gordon Davisson

Posted 2012-11-16T21:14:30.127

Reputation: 28 538

Thanks man! Exactly what I asked. I was bummed out by the fact that I had to logout/login so I did a bit of research. I'll add my finding. – iDev247 – 2012-11-17T05:43:45.070

1

Here is a simpler script that toggles the setting and doesn't activate System Preferences:

tell application "System Preferences"
    reveal pane "com.apple.preference.mouse"
end tell
tell application "System Events" to tell process "System Preferences"
    tell radio group 1 of window 1
        if value of radio button 1 is 1 then
            click radio button 2
        else
            click radio button 1
        end if
    end tell
end tell
quit application "System Preferences"

It doesn't work with the Magic Mouse version of the preference pane.

You can save the script in AppleScript Editor and run it with osascript script.scpt. Or see this question for different ways to assign shortcuts to scripts.

Lri

Posted 2012-11-16T21:14:30.127

Reputation: 34 501

He said "via terminal". – Micheal Johnson – 2015-10-04T14:35:28.330

0

I finally went with this solution.

Another tip that I found in this question is to add the script to the menu bar by doing this:

  1. Open AppleScripts Editor (I just search on Spotlight)
  2. If you don't already have the scripts icon in the menu bar:
    1. Click on AppleScripts Editor in the menu bar
    2. Click Preferences
    3. Enable the checkbox Show Script menu in menu bar. I personally prefer unchecking Show Computer script.
  3. Click on the scripts icon that is now showing on your menu bar
  4. Click on Open Scripts Folder and select Open User Script Folder
  5. Save or copy your script file in this folder (the script I'm using can be found here)
  6. When you want to run the script just click the script icon and select the script

iDev247

Posted 2012-11-16T21:14:30.127

Reputation: 267