Reputation: 1825
I am wondering if there is a way to switch the scroll direction on a mac/osx (yosemite) programatically. If so, I want to assign some sort of script or command to a key combination to switch it quickly. I work on a mac but consistently log into windows computers and my brain wants to scroll the wrong way all the time. I haven't programmed anything on mac, still very new to it, but have done plenty in linux and assume its somewhat similar to bash scripting.
the ultimate end goal would be to have this react to a mouse being plugged in also to change both at the same time if needed, i just think it feels more natural to scroll like a windows pc on a mouse and more natural in the osx way on a trackpad. this is really just for fun and ease of use.
Upvotes: 14
Views: 14143
Reputation: 1
If anyone still looking out post 2025. I'm currently using Sequoia 15.3 and my solutions works.
First you will need to open the terminal and type this:
Then paste the following script
current_status=$(defaults read NSGlobalDomain com.apple.swipescrolldirection)
if [ "$current_status" -eq 1 ]; then
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool false
else
defaults write NSGlobalDomain com.apple.swipescrolldirection -bool true
fi
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u
Then press Ctrl + X, then Y, and press Enter to save and exit.
After that you need to make the script executable, for that you run the following command:
After that's done you need to create a macOS app using Automator. When you first open Automator select Applications as the type of document.
Example of what Automator screen would look like (make sure to update your user)
Once inside you can search for "Run Shell Script" action. Then you want add the full path to the script we just created. Then you save it as an App inside Applications folder.
Last step is to give our new app accessibility options. You will want to go to: Settings > Privacy and Security > Accessibility. Then you want to hit the + icon and add our app to the list and make sure is toggled
Then after that is up to you how you want to automate this even further. You can just have it as an app in your dock, or to take it one step further. What I did is I have BetterTouchTool (I know there are similar free options out there too) and I just created a command that will open the Toggle Natural Scrolling app. And now I just press the correct keys and I can switch the behavior for natural scrolling.
Upvotes: 0
Reputation: 1
I created shortcut from shortcuts app and attached shortcut key to it.
Upvotes: -1
Reputation: 13690
Here is yet another adaptation of the other answers, HOWEVER:
This is the only solution that will allow you to use a key combo from anywhere to immediately reverse scrolling on Mac OS Ventura, without installing any outside applications.
The trick is to create a "Reverse Scrolling" application yourself using Automator, and then use Automator again to create a Quick Action / Service that launches the app when you press the key combo. You need to do this in order to get around permissions issues with AppleScript.
Do not mess around with defaults write
. It will not work.
This solution is tested and confirmed on:
The steps below refer to the System Settings
app. Prior to Mac OS Ventura, this was called System Preferences
.
Command-N
or File > New
to create a new document.Application
as the document type.Run AppleScript
action to the workflow.Command-S
or File > Save As...
to save as "Reverse Scrolling" with File Format Application
in your Applications directory.System Settings > Security & Privacy > Privacy > Accessibility
, add the Reverse Scrolling app (remember, it's in your Applications folder) in the pane that says Allow the apps below to control your computer.
Quick Action
as the document type. This will allow you to add the action to the Services
submenu in every application.Workflow receives no input in any application.
Launch Application
action to the workflow.Other...
.Command-S
or File > Save As...
to save as "Reverse Scrolling". It's fine to use the same name as before.System Settings > Keyboard > Shortcuts > Services
, click Reverse Scrolling
(under the General
subsection in the right checkbox pane) and Add Shortcut
.If you follow all these instructions correctly, you should now have a Reverse Scrolling
menu item under the Services
menu of every application, with your key combo listed next to it.
Test it out by scrolling, observing the scroll direction, pressing the key combo, and repeating the scroll test. Scrolling should have reversed, without any error popups or system requests for permissions.
If anything other than perfect scroll reversal occurs, one of two things has occurred—either you've missed a step, or these instructions have gone out of date.
If you want to undo any of the changes you've wrought, here's how:
System Settings > Keyboard > Shortcuts > Services
and uncheck the box next to Reverse Scrolling
.Library/Services/"Reverse Scrolling.workflow"
(relative to your home directory).System Settings > Security & Privacy > Privacy > Accessibility
and remove Reverse Scrolling
from the list of apps there.Here are two AppleScripts that I've successfully used to reverse scrolling, provided all permissions are in place. These scripts are incredibly fickle and prone to break between versions of Mac OS. By the time you find this answer, you've probably seen several versions of a script that purports to reverse scrolling (though all of them are plagued with permissions errors, unless you carefully follow the steps I've laid out above). If the one for your OS version stops working, and no one has got around to updating this answer, find a different script, but use the rest of the steps above.
Ventura
Works almost every time.
on run {input, parameters}
do shell script "open x-apple.systempreferences:com.apple.Trackpad-Settings.extension"
delay 1.0
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
return input
end run
Monterey
Works every time.
on run {input, parameters}
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 0
end tell
quit application "System Preferences"
return input
end run
Important Final Note
If you ever go back to Automator and edit the Reverse Scrolling app to change the AppleScript, the app will lose the permissions you gave it in step 8 above. You will have to go back to the preference pane from step 8 and fully remove the Reverse Scrolling app (using the –
button) and add it again.
Upvotes: 11
Reputation: 26423
Note:
This works for older version of Macs. You may look into the code in linked repo to adapt for newer though. It worked with v12, not with v13.
I believe many just have the same issue - connect the mouse and want to toggle scroll direction w/o going to the settings.
I actually went an extra step and created guide on this
You can get the zipped application on my github: https://github.com/liesislukas/apple-scroll-direction-auto-toggle or just use link from the article i posted on medium with all the screenshot and documentation.
To clarify, yes I used code from another post on this thread, yet code there was broken. I fixed the code in post above and just packed it up to the application, added nice icon so now it can be added to dock to toggle the mouse direction. Thanks @poddus for giving hint to use the Apple Script :)
Upvotes: 2
Reputation: 29
I know I'm performing some necromancy here, but I figured out how to make this work (prior to Mac OS Ventura), at least partially:
on run {input, parameters}
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 0
end tell
quit application "System Preferences"
return input
end run
Upvotes: 2