Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use mouse with left-hand. My system is shared with other people who are right handed. So, I need frequently to switch mouse button.

I would like to know how to swap mouse button using AppleScript? I am using default mouse come with my iMac machine.

share|improve this question

I only tested this with the normal version of the preference pane, and it doesn't probably work if you have a Magic Mouse:

tell application "System Preferences"
    reveal pane ""
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
            click radio button 1
        end if
    end tell
end tell

The setting is stored in this key, but I don't know any way to apply changes to it immediately:

defaults -currentHost read -g

You could also use KeyRemap4MacBook:

<?xml version="1.0"?>
<autogen>__KeyToKey__ KeyCode::F1, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_swapbuttons</autogen>
<identifier vk_config="true">swapbuttons</identifier>
<autogen>__PointingButtonToPointingButton__ PointingButton::LEFT, PointingButton::RIGHT</autogen>
<autogen>__PointingButtonToPointingButton__ PointingButton::RIGHT, PointingButton::LEFT</autogen>

See the source for the key code values and predefined settings.

share|improve this answer
Thanks for the reply. I got the error error "System Events got an error: Access for assistive devices is disabled." number -1719 from window 1 of process "System Preferences" – doptimusprime Apr 25 '13 at 7:10
You just have to enable access for assistive devices in the accessibility preference pane. – user495470 Apr 25 '13 at 7:14
Now I am getting "System Events got an error: Can’t get radio group 1 of window 1 of process \"System Preferences\". Invalid index." number -1719 from radio group 1 of window 1 of process "System Preferences" – doptimusprime Apr 25 '13 at 7:16
It has drop down under Secondary Click in Point & Click tag. – doptimusprime Apr 25 '13 at 7:17
As mentioned in your answer, my mouse is Magic mouse and it is not working for it. – doptimusprime Apr 25 '13 at 8:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.