System Settings Tab Group and Window Index

Hi all! I had an apple script that I was using to flip the scroll direction when I had a mouse plugged in versus when I was on the go, but the Ventura upgrade broke the script. I’m trying to find an index or some resource that gives the exact tab group and window index of what I’m looking for. Here was the previous script:

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 checkbox 1 of tab group 1 of window "Trackpad"
	
end tell



quit application "System Preferences"

and here’s the current script that I have :

tell application "System Settings"
	open "x-apple.systempreferences:com.apple.Trackpad-Settings.extension"
end tell

tell application "System Events" to tell process "System Settings"
	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 Settings"

but it is unfortunately throwing the following error:
error “System Events got an error: Can’t get tab group 1 of window 1 of process "System Settings". Invalid index.” number -1719 from tab group 1 of window 1 of process “System Settings”

Can anyone help me out?

Hello Andrew !!
You can set the scrolling direction with a shell script…

defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false

false is “Classic” and true for “Natural”

@nico_v This is amazing, Thank you!!! I’m really terrible at applescript, though and I’m struggling to wrap this in an if statement so that it can operate as a switch. The following is throwing an error code that applescript is expecting a comma, but is finding an identifier. Can you please help me fix it?

if (defaults NSGlobalDomain com.apple.swipescrolldirection -bool = false) then
	defaults write NSGlobalDomain com.apple.swipescrolldirection -bool true
else
	defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
end if

I also tried running your script in the terminal, and it wasn’t working to change the scroll direction. Do you know why that is?

Unfortunately the shell script needs the user to logout and log back in. That kills the purpose in your use case…
Haven’t tried it but this App could be a workaround… [Scroll Reverser for macOS]

BTW shell scripts need to be called with do shell script within AppleScripts.
Example :

do shell script "printf 'Hello World'"

The right way to toggle the Value would be :

set scrollSetting to do shell script "defaults read -g com.apple.swipescrolldirection"
if scrollSetting is equal to "1" then
	do shell script "defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false"
else
	do shell script "defaults write NSGlobalDomain com.apple.swipescrolldirection -bool true"
end if