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

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 MouseButtonMode)
echo --- $mmode ---
if [ $mmode = 'TwoButton' ]; then
defaults write "save.MouseButtonMode.v1" -int 2
defaults write MouseButtonMode -string "TwoButtonSwapped"
defaults write "save.MouseButtonMode.v1" -int 1
defaults write 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?

share|improve this question
Have you tried restarting? – Matt Aug 8 '12 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 '12 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 '12 at 9:16
Does the setting stay swapped if you close and reopen Sys Pref? – Matt Aug 8 '12 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 '12 at 10:10

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 ""
    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"
share|improve this answer
System Events got an error: Can’t get radio group 1 of window 1 of process "System Preferences". Invalid index. See – Tal Aug 9 '12 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. – user495470 Aug 9 '12 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 '12 at 6:07

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.