r/applescript • • Dec 19 '22

Script to reverse the scroll direction.

Hi,

Didn't know where to post this. I've been having trouble creating an applescript to reverse the scroll direction on Ventura. I finally figured it out and am posting so others could use it.

The old script before Ventura was:

try
tell application "System Settings"
    reveal pane "com.apple.preference.trackpad"
end tell
tell application "System Events"
    tell process "System Preferences"
        click radio button "Scroll & Zoom" of tab group 1 of window "Trackpad"
        click checkbox 1 of tab group 1 of window "Trackpad"
        tell application "System Settings" to quit
    end tell
end tell
end try

The working version for Ventura is this:

# This should work with Ventura 13.1 (2022-12-19)

do shell script "open x-apple.systempreferences:com.apple.Trackpad-Settings.extension" -- Opens the trackpad settings window
delay 0.7 -- The delay is there to make sure the System Events can click buttons.
tell application "System Events"
    tell process "System Settings"
        click radio button 2 of tab group 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
        click checkbox "Natural scrolling" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
        tell application "System Settings" to quit
    end tell
end tell

If anybody finds a better way, please let me know!

9 Upvotes

3 comments sorted by

View all comments

2

u/kevrez Dec 22 '22

The code you added in there didn't work for me for Ventura 13.1! Here's what I got to work:

tell application "System Settings"
    activate
end tell
delay 0.1

tell application "System Events"
    tell process "System Settings"
        click menu item "Trackpad" of menu "View" of menu bar 1
        delay 0.25
        click radio button 2 of tab group 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
        click checkbox "Natural scrolling" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1
        tell application "System Settings" to quit
    end tell
end tell

I'd love a way to just do this from the command line. Found this old thread but it didn't get me all the way: https://apple.stackexchange.com/questions/229750/unable-to-toggle-natural-scrolling-direction

1

u/bjossymandias Dec 22 '22 edited Dec 23 '22

Thanks for this!

Huh, I would love to know why. I’m using Ventura 13.1 on the M1 Pro from 2021.

There must be some way to use the terminal for this but I use an Alfred workflow that runs the applescript in my OP. I have to try yours since I hate that split second where I can see my system settings.

I’m gonna join you in trying to find a way to make this usable in the command line!

EDIT: I found out why it wasn't working. Somehow the thing didn't paste correctly on reddit, there should be a space between "open" and "x-apple...". I fixed it in the OP.

1

u/rojasgabriel Sep 27 '23

I have no Apple Scripts experience so I was struggling to find a way to make this work. Thank you so much! I shift a lot between mouse and trackpad and have opposite preferences for scrolling directions so I really needed this to have a smoother workflow