10

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?

2 Answers 2

7

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
3
  • Odd that you have to specify a click location for this tab just to get it to open but not for the other 4 tabs of the 'Keyboard' prefs pane, but I'll take it! I appreciate the help and i just wish I understood why it was necessary (for my own script problem-solving in the future). Thank you.
    – NYKg
    Commented Jan 16, 2017 at 5:47
  • @NYKg, I can't tell you why reveal anchor "Dictation" of pane id "com.apple.preference.keyboard" doesn't work like with the other anchors on that pane. It didn't work of me either and why I took an alternate route, which sometimes it what one has to do to get the job done. :) Commented Jan 16, 2017 at 12:26
  • Some people may find that a longer delay (1.5 or 2) makes this script more reliable.
    – Dave Land
    Commented Apr 6 at 22:40
2

I wanted to do something like this for the Arrangement tab of the Display pane. Unfortunately these names have a habit of changing from time to time, but for now under Big Sur, this works, exclusively using the System Preferences dictionary and no need for System Events:

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

If you need a different tab (not all of them are totally intuitively named), you can run this to get a list of all the tabs in the pane you're interested in. e.g. for the Display pane:

tell application "System Preferences"
    activate
    set current pane to pane id "com.apple.preference.displays"
    anchors of current pane
end tell

In the Result pane of the AppleScript Editor window, you'll see something like this:

{anchor "displaysDisplayTab" of pane id "com.apple.preference.displays" of application "System Preferences", anchor "displaysNightShiftTab" of pane id "com.apple.preference.displays" of application "System Preferences", anchor "displaysArrangementTab" of pane id "com.apple.preference.displays" of application "System Preferences", anchor "displaysColorTab" of pane id "com.apple.preference.displays" of application "System Preferences", anchor "displaysGeometryTab" of pane id "com.apple.preference.displays" of application "System Preferences"}

So in my case, the anchor name for the Arrangement tab is displaysArrangementTab.

1
  • reveal anchor "displaysArrangementTab" of current pane does the trick. Thank you!
    – Dave Land
    Commented Apr 6 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .