How to map the bottom right Trackpad corner to right-click programmatically?

I’m looking for a command (defaults write …) to enable right-click by tapping the bottom right Trackpad corner.

This can be enabled as follows: System PreferencesTrackpadPoint & Click → enable Secondary click and select “Click in bottom right corner”.

However, I’m looking for a way to do this programmatically.

More details

To find out which settings to modify using the defaults command, I usually do something like this…

  1. Disable the desired setting in System Preferences and close the preference pane.
  2. Then:

    cd /tmp
    defaults read > before
    
  3. Then, change the setting in System Preferences and close the preference pane. 4.

    defaults read > after
    diff before after
    

A long time ago (I think it was still on Snow Leopard) this brought up the following solution:

# Map bottom right Trackpad corner to right-click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true

However, it seems like there’s more to it than just these two settings. I’ve tried disabling the setting in System Preferences, then running these commands, then logging out and back in again, but it had no effect.


Solution 1:

I spent some more time debugging this, and it seems there are multiple setting locations (on multiple hosts) for the same setting.

AFAICT, each user gets his own host. The login screen uses a separate host. It makes sense to enable some settings (like Trackpad tap to click) for both these hosts.

Furthermore, OS X seems to have separate settings for Magic Trackpads and built-in MacBook Trackpads. The commands in my question only enable the Magic Trackpad settings.

Now, I try to enable it everywhere:

# Map bottom right Trackpad corner to right-click
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadCornerSecondaryClick -int 2
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadRightClick -bool true
defaults -currentHost write NSGlobalDomain com.apple.trackpad.trackpadCornerClickBehavior -int 1
defaults -currentHost write NSGlobalDomain com.apple.trackpad.enableSecondaryClick -bool true