Is there a good resource for learning how to generate paths to UI elements in System Settings for AppleScript? Specifically, I am trying to access the keyboard scrolling button in the Accessibility setting, so I can toggle it with AppleScript. Xcode's Accessibility Inspector gives a general path, but doesn't give clear detail (such as ". . . group 1 of splitter group 1 of group 2 of window 2 of . . ."). Anything useful would be helpful — a tutorial on how to build the path, a piece of code to generate the path, an app that will generate the path, etc. I would be grateful for any suggestions!
-
Does latenightsw.com/freeware/ui-browser help?– GilbyCommented Jun 18, 2023 at 23:13
-
There are several questions here (and on stackoverflow) that provide methods for determining the complete path. Try searching and you may find your solution.– MockmanCommented Jun 19, 2023 at 2:51
-
Gilby, thanks for your suggestion. It seems, though, that the UI Browser has been discontinued as of 2022; and the download on your latenightsw page doesn't seem to offer any function unless one already has an (previously purchased) license for UI Browser.– Mark KupkeCommented Jun 20, 2023 at 2:09
-
Mockman, I have been searching StackExchange and other sites for weeks to find a workable method for determining the complete path. I have found sites that offer solutions for finding a path to one specific element in System Settings, but none that show me how to determine the path to any desired element. If you know of any specific pages that offer this, I would love to have links to them. Thanks.– Mark KupkeCommented Jun 20, 2023 at 2:16
1 Answer
Actually, I've finally been able to piece it together using the Accessibility Inspector, after all. It's taken some doing; and I still haven't figured out how to get the script to run while keeping System Settings hidden, which would be ideal.
But here's the script that does indeed toggle the Trackpad Scrolling option (the setting of visibility to false near the top has the effect of moving the System Settings window below the Script Editor window only, still not invisible) — afraid the formatting looks sloppy here, as the text box is narrower than in Script Editor:
do shell script "open -b com.apple.systempreferences " & ¬
"/System/Library/PreferencePanes/UniversalAccessPref.prefPane"
tell application "System Events"
tell its application process "System Settings"
delay 0.1
set visible to false
repeat until UI element 3 of group 3 of scroll area 1 of group 1 of ¬
group 2 of splitter group 1 of group 1 of window "Accessibility" exists
delay 0.1
end repeat -- find Pointer Control option in Accessibility settings
click UI element 3 of group 3 of scroll area 1 of group 1 of group 2 ¬
of splitter group 1 of group 1 of window "Accessibility"
delay 0.1 -- click Pointer Control option
repeat until button 1 of scroll area 1 of group 1 of group 2 of splitter group 1 ¬
of group 1 of window "Pointer Control" exists
delay 0.1
end repeat -- find Trackpad Options button in Pointer Control
click button 1 of scroll area 1 of group 1 of group 2 of splitter group 1 ¬
of group 1 of window "Pointer Control" -- click Trackpad Options button
repeat until checkbox 1 of group 1 of scroll area 1 of group 1 of sheet 1 ¬
of window "Pointer Control" exists
delay 0.1
end repeat -- find Use Trackpad for Scrolling checkbox in Trackpad Options
click checkbox 1 of group 1 of scroll area 1 of group 1 of sheet 1 ¬
of window "Pointer Control" -- toggle Use Trackpad for Scrolling checkbox
repeat until button 2 of group 1 of sheet 1 of window "Pointer Control" exists
delay 0.1
end repeat -- find OK button in Trackpad Options
click button 2 of group 1 of sheet 1 of window "Pointer Control"
end tell
end tell
delay 0.1
tell application "System Settings" to quit