How to apply written defaults to a Magic Mouse (com.apple.driver.AppleBluetoothMultitouch.mouse)? 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?
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"