Running OSX 10.7.4
I wrote a script to swap Apple Magic Mouse secondary click.

The following simple bash script do modify the system preferences (can be seen in System Preferences GUI), but the mouse secondary click is not really swapped.

mmode=$(defaults read  com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode)
echo --- $mmode ---
if [ $mmode = 'TwoButton' ]; then
defaults write  com.apple.driver.AppleBluetoothMultitouch.mouse "save.MouseButtonMode.v1" -int 2
defaults write  com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode -string "TwoButtonSwapped"
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse "save.MouseButtonMode.v1" -int 1
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode -string "TwoButton"

It seems the OS needs some reload/refresh command for the change to take effect. Can anyone figure out what I'm missing?

  • Have you tried restarting?
    – Matt
    Aug 8, 2012 at 8:18
  • restarting?! of course not. System Preferences GUI works well. I just need a shortcut script launched to avoid 5 clicks every time I need to swap hands
    – Tal
    Aug 8, 2012 at 9:09
  • Also, I know it can be done with Automator Watch-Me-Do. But I will need two different Automator scripts since Watch-Me-Do can't be branched
    – Tal
    Aug 8, 2012 at 9:16
  • Does the setting stay swapped if you close and reopen Sys Pref?
    – Matt
    Aug 8, 2012 at 9:38
  • if I reopen Sys Pref settings stay swapped but has not effect until I open and click on the currently selected mode.
    – Tal
    Aug 8, 2012 at 10:10

1 Answer 1


I couldn't find any way to apply the changes, but you could also use UI scripting to change the setting.

tell application "System Events" to tell process "System Preferences"
        set visible to false
    end try
    tell application "System Preferences" to reveal pane id "com.apple.preference.mouse"
    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
quit application "System Preferences"
  • System Events got an error: Can’t get radio group 1 of window 1 of process "System Preferences". Invalid index. See images.apple.com/magicmouse/images/software.jpg
    – Tal
    Aug 9, 2012 at 5:48
  • I only have 10.8 and no Magic Mouse. If someone gets the script to work with the Magic Mouse style preference pane or in older versions, feel free to edit the answer.
    – Lri
    Aug 9, 2012 at 6:03
  • unfortunately apple script record won't capture sys perf actions. Automator does, but it won't reveal how it is done. I couldn't find any apple script example similar to the magic mouse windows :-(
    – Tal
    Aug 9, 2012 at 6:07

You must log in to answer this question.

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