5

I prefer "natural" scroll direction when using my MBAir trackpad, but "unnatural" when using the mouse. I frequently switch back and forth depending on where I'm working, so I've been using a bit of AppleScript to switch the setting. This script stopped working when I upgraded to Mac OS Yosemite. It still opens the Scroll & Zoom pane of the Trackpad preferences, but it doesn't click the checkbox. I've tried a few things but I can't get it to work.. I'm not an Apple Developer, so I don't have any debugging tools. Any tips?

try
    tell application "System Preferences"
        activate
        set current pane to 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"
        end tell
    end tell
end try
3

First, make sure Applescripts has permission to modify apps. This can be done by opening System Preferences | Security & Privacy | Accessibility and checking Script Editor. This is a one time process and you shouldn't have to check it again.

I ran this same snippet @Bowen provided in his question on Mojave and noticed what he described. I fixed it by adding the delay mentioned by @Bowen in his answer. The box would either check or uncheck now that we have added a small delay.

Here is that example I ran directly from Script Editor:

try
tell application "System Preferences"
    activate
    set current pane to pane "com.apple.preference.trackpad"
end tell
delay 2
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 Preferences" to quit
    end tell
end tell
end try

Also, In relation to this topic, I built something using ideas from this thread, since folks may want to automate it per their settings. The below script is "Automator ready", or can be exported as an application so you can run it at startup or however you want to execute it. You have to also allow access to the exported application as shown in the image above for "Scroll direction Clicker". This is specific to a Logitech mouse being found, but it can easily be modified to any other type of string/mouse type. It can also be used as a decent reference to build off of for scroll-direction. I for one got tired of flipping scroll-direction when going from mouse to trackpad, and that's how I found this thread.

Tailored to be exported as an Application from within Script Editor

try
    set logitech to "Logitech"
    try
        set scriptOutput to do shell script "system_profiler SPUSBDataType | grep -i logitech"
        if scriptOutput contains logitech then
            tell application "System Preferences"
                activate
                set current pane to pane "com.apple.preference.trackpad"
            end tell
            delay 2
            tell application "System Events"
                tell process "System Preferences"
                    set checkBoxOne to checkbox 1 of tab group 1 of window "Trackpad"
                    click radio button "Scroll & Zoom" of tab group 1 of window "Trackpad"
                    tell checkBoxOne to if value is 1 then click
                    tell application "System Preferences" to quit
                end tell
            end tell
        end if
    on error errMsg
        log errMsg
        tell application "System Preferences"
            activate
            set current pane to pane "com.apple.preference.trackpad"
        end tell
        delay 2
        tell application "System Events"
            tell process "System Preferences"
                set checkBoxOne to checkbox 1 of tab group 1 of window "Trackpad"
                click radio button "Scroll & Zoom" of tab group 1 of window "Trackpad"
                tell checkBoxOne to if value is 0 then click
                tell application "System Preferences" to quit
            end tell
        end tell
    end try
end try
  • I'm using your 1st example in an Automator service. When I trigger it from another app (say, Safari), the Security and Privacy area wants me to grant access for that app to control System Preferences and System Events. I don't necessarily want to do that, nor do I want to have to authorize each app that I may have open. Is there any way around this? Do I have something configured incorrectly? Or is this just part of the Mojave security changes? – TimSum Feb 14 at 6:49
  • 1
    I updated my answer to show that you should only have to grant access once. After that, you shouldn't have to continuously do that. Also, as far as I know, you cannot run a script/Automator without granting it access as this is a security concern and by approving it you're consenting to that risk–even if it's not a risky program. – TODO Feb 15 at 1:01
1

I answered my own question: If this script isn't working, go to System Preferences | Security & Privacy | Accessibility, and make sure that Script Editor is checked ON to allow Applescripts to control the GUI.

0

So what was happening was it was cycling thought the code to fast. So what i did was put delays in between where it wasn't working and it works perfectly fine. If you want to you could reduce the delay down to 0.5 or 0.2

tell application "System Preferences" activate set current pane to pane "com.apple.preference.trackpad" end tell

tell application "System Events" tell process "System Preferences" delay (1) click radio button "Scroll & Zoom" of tab group 1 of window "Trackpad" delay (1) click checkbox 1 of tab group 1 of window "Trackpad" delay (1) end tell end tell

0

You can solve this without any applescript: https://pilotmoon.com/scrollreverser/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .