I just got keyboard maestro recently and I have a question.
I figured out how I can open up system preferences at the 'keyboard' pane but I want to open it at a specific point in that pane.
After it opens, I want for it to automatically go to 'shortcuts' and then to 'app shortcuts'. I don't really have a solution to it. What is the best way to go about it?
There is probably an AppleScript solution. Otherwise, you need to pause until the window appears and then click on the Shortcuts title, and then pause until the animation completes.
------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/07/26 03:53
# dMod: 2016/04/15 09:08
# Appl: System Preferences & System Events
# Task: Bring up System Prefs with App Shortcuts Selected
# Tags: @Applescript, @Script, @System_Events, @System_Preferences, @Keyboard, @App_Shortcuts
------------------------------------------------------------
with timeout of 10 seconds
tell application "System Preferences"
if not running then run # Works around 'activate' bug.
reveal anchor "shortcutsTab" of pane id "com.apple.preference.keyboard"
activate
end tell
tell application "System Events"
tell process "System Preferences"
set frontmost to true
tell (first window whose subrole is "AXStandardWindow")
repeat until table 1 of scroll area 1 of splitter group 1 of tab group 1 exists
delay 0.1
end repeat
tell table 1 of scroll area 1 of splitter group 1 of tab group 1
tell last row
set value of attribute "AXSelected" to true
end tell
end tell
end tell
end tell
end tell
end timeout
------------------------------------------------------------
Thank you for that. I should really learn applescript, it’s pretty straightforward it seems but you have to know all these processes. I don’t really know how one even finds information to write this line : ‘repeat until table 1 of scroll area 1 of splitter group 1 of tab group 1 exists’.
I use UI Browser for such things, but at $55.00 U.S. it’s a bit expensive for most non-professional scripters. I bought it over a decade ago after discovering how convoluted GUI-Scripting was, and I’ve never regretted spending the money.
Xcode comes with the Accessibility Inspector utility, which is useful but not nearly as helpful as UI Browser.
There are other fairly brute-force discovery methods as well.
Slightly modified @ccstone 's script to open Security and Privacy preference pane, select 'Accessibility' and click the Lock icon:
with timeout of 10 seconds
tell application "System Preferences"
if not running then run # Works around 'activate' bug.
reveal anchor "privacy" of pane id "com.apple.preference.security"
activate
end tell
tell application "System Events"
tell process "System Preferences"
set frontmost to true
tell (first window whose subrole is "AXStandardWindow")
repeat until table 1 of scroll area 1 of tab group 1 exists
delay 0.1
end repeat
tell table 1 of scroll area 1 of tab group 1
tell row 9
set value of attribute "AXSelected" to true
end tell
end tell
click button "Click the lock to make changes."
end tell
end tell
end tell
end timeout
Also, if future readers want to amend this script for some other preference pane, navigate to the said preference pane and use this applescript snippet:
tell application "System Preferences"
set thePane to the id of the current pane
display dialog thePane
end tell
This example will show com.apple.preference.security when 'Security & Privacy' is open.