Toggle Scroll Direction from Natural to Normal

I like to use the Natural scroll direction when using a trackpad, but the normal scroll direction when using a mouse.

I work with a dock at home with a full mouse and keyboard setup, but frequently take my MacBook out into the world with me. I found it super frustrating to have to manually change the scroll direction every single time I did this and I wanted to share it - this is by far my most used Macro.

The Macro is triggered with a Hotkey that I have bound to :arrow_up:⌥S

I have edited another Macro that was similar to this that I found on here awhile ago and just cannot locate to give credit. That went through the mouse system preference to change the direction, but that wouldn't work if you didn't have a mouse connected. If you do know where it came from, please let me know and I'll link it.

Toggle Natural Scroll.kmmacros (2.1 KB)

1 Like

This is great, thank you! I hope I'll be able to do it automatically when mouse is attached/removed, looks like there is a USB device trigger

Yep, I got it working with the help of USB Device condition

image

That's great that you got it set up for USB. I have it triggered with the key binding since there isn't a good trigger for a bluetooth mouse.

Thanks.

I guess Bluetooth devices will not work with USB trigger.

The device name shows under system devices for bluetooth, so I wonder if there is a way to get this working.

I end up with a more complex macro, which is still based on your AppleScript. I check for KBM engine start, unlock event, mouse connect/disconnect. It was a bit tricky because it looks like if you have 2 profiles and toggle between them, variables may conflict with each other :thinking:

Anyway here is my take if anyone want to try (macro is disabled by default)

Toggle Natural Scroll.kmmacros (6.9 KB)

Here's a place to start.

If you search the forum for bluetooth, you'll probably find some more.

Also Google: mac shell detect bluetooth device - Google Search

So the upgrade to Ventura looks like it's broken this. I've managed to figure out how to open and find the trackpad pane, but It's throwing an invalid index error. Here is the script that I have so far:

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 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?

I've been able to partially fix the applescript, although I don't like it as much since it brings the system settings panel to the front to execute the script. Any help in keeping the process in the background like it used to be would be appreciated. Here's the Script

tell application "System Settings"
	activate
end tell

open location "x-apple.systempreferences:com.apple.Trackpad-Settings.extension"
delay 0.5




tell application "System Events" to 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 "Trackpad"
	click checkbox 0 of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Trackpad"
end tell

quit application "System Settings"

Hey Andrew,

I'm still on Mojave, so you'll need to change “System Preferences” to “System Settings” in the script.

I won't guarantee the object hierarchies are correct for your version of macOS either, but they will possibly work as is and should otherwise be amenable to adjustment.

This script does not require the app to activate and become visible.

A lot of people think one-line System Events references are cool, and a structured tree is gross – but I'll tell you what – when you need to make changes the tree is way easier to work with.

-Chris

--------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2023/01/26 18:05
# dMod: 2023/01/26 18:05 
# Appl: System Events, System Preferences
# Task: Toggle “Natural” Scroll Direction in System Preferences
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @System_Preferences
# Test: macOS 10.14.6 Mojave
# Vers: 1.0
--------------------------------------------------------

set |timeOut| to 5
set _cntr to 0

tell application "System Preferences"
   if not running then run
   reveal pane id "com.apple.preference.trackpad"
   repeat until window "Trackpad" exists
      set _cntr to _cntr + 0.25
      if _cntr > |timeOut| then error "Script has timed-out!"
      delay 0.25
   end repeat
end tell

tell application "System Events"
   tell application process "System Preferences"
      tell window "Trackpad"
         tell tab group 1
            
            tell radio button "Scroll & Zoom"
               perform action "AXPress"
            end tell
            
            tell checkbox 1
               perform action "AXPress"
            end tell
            
         end tell
      end tell
   end tell
end tell

tell application "System Events" to quit

--------------------------------------------------------

Hi @ccstone I tried to run your script after changing "System Preferences" to "System Settings", but it threw this error -

**error** "System Settings got an error: AppleEvent handler failed." number -10000

at the line

reveal pane id "com.apple.preference.trackpad"

Any ideas on how to fix it?

Run this in Script Debugger or Apple's Script Editor and see if you get a result:

tell application "System Settings"
   return panes whose name contains "trackpad"
end tell

Hi @ccstone Nope, it threw the following error -

error "System Settings got an error: AppleEvent handler failed." number -10000

Download Script Debugger.

Plug for SD...

Run, don’t walk over to Late Night Software and download Script Debugger. Even if you don’t buy a copy and instead use the freeware “Lite” version it is far, far superior to Apple’s painfully decrepit and neglected Script Editor.

  • Regex find/replace support.
  • Step through your code line by line (commercial only).
  • Breakpoints (commercial only).
  • Script Debugger Feature Comparison
    • Literally hundreds of more features...

Drop the System Settings app on it in the Finder – or use the Open Dictionary mechanism in SD.

This will open the System Settings AppleScript Dictionary.

From there you'll have to do some detective work.

You can use Apple's decrepit Script Editor app for this, but it's anemic compared to event the “lite” (freeware) version of SD.

I think System Setting's AS support is (still|again) broken in Ventura.

tell application "System Settings"
	return every pane
end tell
-> error "System Settings got an error: AppleEvent handler failed." number -10000

Similarly with current pane, etc.

So you may have to use UI scripting to get the correct pane up in the first place.

1 Like

Thanks for testing!