Help with a simple macro to open system preferences keyboard at 'shortcuts' tab

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?

Here is what I have so far :slight_smile:

Thank you for any help.

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.

Yep.   :slight_smile:

------------------------------------------------------------
# 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

------------------------------------------------------------

-Chris

2 Likes

wow that is great.

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’.

Hey Nikita,

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.

References For Learning & Using Applescript

Learning & Using AppleScript & JavaScript for Automation (JXA)

-Chris

Fortunately, you do NOT have to download Xcode to get the Accessibility Inspector.

See OS X Accessibility Inspector (UIElementInspector) Tool for UI Scripting

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
1 Like

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.

1 Like

These IDs can also be used in URL calls. I've come up with a tool for accessing Preferences that includes a method to add new ones according to your AppleScript and also an optional conditional pause at the end.

If anyone knows of a cleaner way to return the second half of a split variable value, please let me know. The Get Preference Name action identifies the correct line in the list and returns the part after the __ in order to do this.

Open System Preference.kmmacros (55 KB)

Macro screenshot