Swap Mouse Button using AppleScript 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.
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 "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


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

defaults -currentHost read -g com.apple.mouse.swapLeftRightButton


You could also use KeyRemap4MacBook:

&lt;?xml version="1.0"?&gt;
&lt;root&gt;
&lt;item&gt;
&lt;name&gt;test&lt;/name&gt;
&lt;identifier&gt;test&lt;/identifier&gt;
&lt;autogen&gt;__KeyToKey__ KeyCode::F1, VK_COMMAND | ModifierFlag::NONE, KeyCode::VK_CONFIG_TOGGLE_swapbuttons&lt;/autogen&gt;
&lt;/item&gt;
&lt;item&gt;
&lt;name&gt;swapbuttons&lt;/name&gt;
&lt;identifier vk_config="true"&gt;swapbuttons&lt;/identifier&gt;
&lt;autogen&gt;__PointingButtonToPointingButton__ PointingButton::LEFT, PointingButton::RIGHT&lt;/autogen&gt;
&lt;autogen&gt;__PointingButtonToPointingButton__ PointingButton::RIGHT, PointingButton::LEFT&lt;/autogen&gt;
&lt;/item&gt;
&lt;/root&gt;


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