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

system_preferences

#1

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.


Go directly to App Shortcuts in System Preferences
#2

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.


#3

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


#4

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


#5

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


#6

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

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