How to set up a keyboard shortcut on my Mac to change scroll direction?

9.7k views Asked by At

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.

5

There are 5 answers

4
Lukas Liesis On

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

https://medium.com/@liesislukas/how-to-set-scroll-direction-independently-for-mouse-and-trackpad-on-macbook-66bb6812678

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 :)

enter image description here

0
Kevaldholakiya On

I created shortcut from shortcuts app and attached shortcut key to it.

3
user513951 On

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:

  • Mac OS Ventura v13.2
  • Mac OS Monterey v12.4

The steps below refer to the System Settings app. Prior to Mac OS Ventura, this was called System Preferences.

  1. Launch Automator.
  2. Use Command-N or File > New to create a new document.
  3. Choose Application as the document type.
  4. Add a Run AppleScript action to the workflow.
  5. Enter one of the AppleScripts at the bottom of this answer (see notes). Don't worry if running it at this point gives you permissions errors.
  6. Use Command-S or File > Save As... to save as "Reverse Scrolling" with File Format Application in your Applications directory.
  7. Close the Automator document.
  8. Under 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.
  9. Go back to Automator and create a new document.
  10. This time, choose Quick Action as the document type. This will allow you to add the action to the Services submenu in every application.
  11. Configure the workflow so that it requires no input. The top of the document edit pane should say Workflow receives no input in any application.
  12. Add a Launch Application action to the workflow.
  13. In the application chooser dropdown, select Other....
  14. In the finder window that pops up, navigate to your Applications directory and choose the Reverse Scrolling app.
  15. Use Command-S or File > Save As... to save as "Reverse Scrolling". It's fine to use the same name as before.
  16. Under System Settings > Keyboard > Shortcuts > Services, click Reverse Scrolling (under the General subsection in the right checkbox pane) and Add Shortcut.
  17. Press the key combination you want to use. Note that you'll have to avoid collisions with any other key combination, so choose carefully.

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:

  • To get rid of the keyboard shortcut, go back to System Settings > Keyboard > Shortcuts > Services and uncheck the box next to Reverse Scrolling.
  • To get rid of the Service completely, delete the directory Library/Services/"Reverse Scrolling.workflow" (relative to your home directory).
  • To rescind permissions for the app, go back to System Settings > Security & Privacy > Privacy > Accessibility and remove Reverse Scrolling from the list of apps there.
  • To get rid of the app completely, delete it from your Applications directory.

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.

3
poddus On

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:

  • Create a new Service with Automator
  • Service receives no Input and only runs in Finder (this is important for Permissions reasons, see below)
  • under utilities, add the action "Run AppleScript"
  • use this code
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
  • Save
  • Go to System Preferences -> Security & Privacy -> Privacy -> Accessibility
  • Add Finder.app (/System/Library/CoreServices/Finder.app)
  • Go to System Preferences -> Keyboard -> Shortcuts -> Services
  • Add a keyboard shortcut to your service
  • ???
  • Profit
4
AndrewO On

I found an answer here using the defaults command:

Write with: defaults write -g com.apple.swipescrolldirection -bool FALSE (or TRUE)

Read the current value with: defaults read -g com.apple.swipescrolldirection.