5

I'm looking to make a script that quickly toggles the Natural scrolling settings, so I need a way to do it from the command line.

I think I found the correct defaults command, but I'm not sure how to apply it without logging out. Here is the command I'm using:

defaults write ~/Library/Preferences/.GlobalPreferences com.apple.swipescrolldirection -bool

4

The same setting is visible in the Magic Mouse and Trackpad panes. This works if you have a Magic Mouse connected (but not if you do not):

osascript -e 'tell application "System Preferences"
    reveal anchor "mouseTab" of pane id "com.apple.preference.mouse"
end tell
tell application "System Events" to tell process "System Preferences"
    click checkbox 1 of window 1
end tell
quit application "System Preferences"'

This works if you have a trackpad:

osascript -e 'tell application "System Preferences"
  reveal anchor "trackpadTab" of pane id "com.apple.preference.trackpad"
end tell

tell application "System Events" to tell process "System Preferences"
    click radio button 2 of tab group 1 of window 1
    click checkbox 1 of tab group 1 of window 1
end tell

quit application "System Preferences"'

nb: the "Accessibility Inspector" tool that comes with Xcode can be used to locate UI items to click on.

You must log in to answer this question.

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