Changing trackpad scroll direction with AppleScript in Yosemite
Solution 1:
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
Solution 2:
Change "activate" to "run" to make the script run in the background. also add "quit" to the end of the script with a delay of 0.6 to quit system preferences after executing the script.
try
tell application "System Preferences"
(run)
set current pane to pane "com.apple.preference.trackpad"
end tell
tell application "System Events"
tell process "System Preferences"
delay 0.6
click radio button "Scroll & Zoom" of tab group 1 of window "Trackpad"
click checkbox 1 of tab group 1 of window "Trackpad"
end tell
tell application "System Preferences" to quit
end tell
end try