MacOS – Using AppleScript to launch specific tabs in System Preferences panes

applescriptmacossystem-prefs

So I'm new to this and I might be overlooking something simple, but after failing to figure it out myself I attempted to follow the instructions from grgarside's solution to this question:
https://apple.stackexchange.com/a/250276/220050

What I am trying to do is open 'System Preferences > Keyboard > Dictation' (in Sierra, 10.12.2) using an AppleScript saved as an Application I've created via Automator. I've managed to open all of the other tabs within the 'Keyboard' pane (Keyboard, Text, Shortcuts, & Input Sources) using their anchors as part of an AppleScript but not 'Dictation', the 5th and final tab.

This is my current script, which opens 'System Preferences > Keyboard' but then halts with no error message. (I did note that it activates the Search field within the Keyboard pane though, which it does not do when scripted for the other 4 tabs)

tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.keyboard"
reveal anchor "Dictation" of pane id "com.apple.preference.keyboard"
end tell

Any advice?

Best Answer

The following works for me under macOS Sierra:

tell application "System Preferences"
    activate
    set current pane to pane id "com.apple.preference.keyboard"
    delay 1
    tell application "System Events"
        click radio button "Dictation" of tab group 1 of window "Keyboard" of application process "System Preferences"
    end tell
end tell