I stumbled upon this simple AppleScript while looking for something else, but it's incredibly useful for scripting System Settings…so I'm posting it here in case the original site ever goes away.
To get the names of all the anchors for a selected pane in System Settings, just run this in Script Editor:
1 2 3 | tell application "System Settings" get every anchor of current pane end tell |
Run that on the Desktop pane, for instance, and the output is this:
{anchor "Dock" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings", anchor "HotCorners" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings", anchor "MenuBar" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings", anchor "MissionControl" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings", anchor "Shortcuts" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings", anchor "StageManager" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings", anchor "WindowsApps" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings"}
With that information, you can jump directly to a given area in AppleScript with code like this:
1 2 3 4 5 6 | tell application "System Settings" activate reveal anchor "Shortcuts" of pane id "com.apple.Desktop-Settings.extension" of application "System Settings" delay 0.5 -- macro does other stuff here… end tell |
I'd always wondered how people found the anchor names, and now I know.
Very useful! Out of interest, what's the point of 'delay 0.5' at the end? Presumably if you just want to show a settings area it's not needed, but if your script is then going to do something you need a delay for the transition animation to finish?
Yea, that's it—if you don't insert the delay, whatever steps you're going to take on that panel won't process as it's not been loaded. And depending on the speed of the Mac, you might have to vary the delay. (Though I think it's also possible to wait until something on the chosen pane is visible, which would be a better solution.)
-rob.
I do that Rob: I add an empty repeat loop, 'repeat until the name of window 1 is "Accessibility"¬ end repeat"', for example.