1

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.

2

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:

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

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

  • 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. – Lri 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .