Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

#!/bin/bash
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"
echo LEFT HAND MODE
else
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse "save.MouseButtonMode.v1" -int 1
defaults write com.apple.driver.AppleBluetoothMultitouch.mouse MouseButtonMode -string "TwoButton"
echo RIGHT HAND MODE
fi

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
show 6 more comments

1 Answer

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"
    try
        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
        else
            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 images.apple.com/magicmouse/images/software.jpg –  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. –  Lri 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
add comment

Your Answer

 
discard

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.