2

Applescripts for Ventura's new System Settings

My old Applescript stopped working on Ventura. Any ideas on how to fix this script?

tell application "System Preferences"
        reveal anchor "TextToSpeech" of pane id "com.apple.preference.universalaccess"
    end tell
    
    tell application "System Events" to tell process "System Preferences"
        set theCheckbox to checkbox "Speak items under the pointer" of group 1 of window "Accessibility"
        tell theCheckbox
            set checked to true
            click theCheckbox
        end tell
    end tell

3 Answers 3

2

This following AppleScript code works for me on macOS Ventura

do shell script "open -b com.apple.systempreferences " & ¬
    "/System/Library/PreferencePanes/UniversalAccessPref.prefPane"

tell application "System Events"
    tell its application process "System Settings"
        repeat until UI element 4 of group 1 of scroll area 1 of group 1 of ¬
            group 2 of splitter group 1 of group 1 of window "Accessibility" exists
            delay 0.1
        end repeat
        click UI element 4 of group 1 of scroll area 1 of group 1 of group 2 ¬
            of splitter group 1 of group 1 of window "Accessibility"
        repeat until checkbox 3 of group 2 of scroll area 1 of group 1 of group ¬
            2 of splitter group 1 of group 1 of window "Spoken Content" exists
            delay 0.1
        end repeat
        click checkbox 3 of group 2 of scroll area 1 of group 1 ¬
            of group 2 of splitter group 1 of group 1 of window "Spoken Content"
    end tell
end tell

tell application "System Settings" to quit
7
  • 1
    God help you if the UI changes.
    – benwiggy
    Commented Nov 10, 2022 at 17:26
  • A pretty solid script. Nice implementation of UI element checkpoints. Code could use a tidy up, as you've got repeated references all over the shop, which is an eye-sore. I would +1 this, but it's let down by the needless do shell script call 😩
    – CJK
    Commented Nov 10, 2022 at 23:07
  • @CJK I removed unnecessary lines of code. I'm still going to have to stick with my choice of using do shell script since the reveal anchor or reveal pane... currently does not work on OS Ventura.
    – wch1zpink
    Commented Nov 10, 2022 at 23:52
  • What might the open command in terminal be doing if you were to hazard a guess ? There are three components to it: the command itself (open), the application's bundle identifier (which could have alternatively been the application's name with the -a option, but bundle identifiers are good), and a path to a file. Are we to believe that this is a specialised function that only the shell provides access to...? In fact, there's a reasonable chance that the shell command is a wrapper for an Apple events call. But, to be fair, it works, and it's simple, and it'll likely never break.
    – CJK
    Commented Nov 11, 2022 at 0:35
  • The use of the do shell script open command is the only way (as far as I can tell… For now) to go directly to the Accessibility controls in System Settings.app (formerly System Preferences), without having to use UI Scripting. OS Ventura broke the ability to use tell application "System Preferences" to reveal...
    – wch1zpink
    Commented Nov 11, 2022 at 0:47
2

The name of the "System Preferences" app has changed to "System Settings", and the app's UI has changed too.

the "Speak items under the pointer" item is put in "Spoken Content" now.

I am not familiar with AppleScript, but I tried to implement it with JavaScript.

Is this what you expected

#!/usr/bin/env osascript -l JavaScript
// Reveal System Settings
Application("System Settings").reveal()
const settings = Application("System Events").applicationProcesses.byName("System Settings")

// Focus on it
settings.frontmost = true

// Wait for System Settings window appearing
delay(0.5)

// Reveal Accessibility panel
settings.menuBars[0].menuBarItems["View"].menus["View"].menuItems["Accessibility"].click()

// Wait for panel switching
delay(0.5)

// Click Spoken Content
settings.windows[0].groups[0].splitterGroups[0].groups[1].groups[0].scrollAreas[0].groups[0].buttons[3].click()

// check the Speak item under the pointer checkbox
const checkbox = settings.windows[0].groups[0].splitterGroups[0].groups[1].groups[0].scrollAreas[0].groups[1].checkboxes["Speak item under the pointer"]
if (checkbox.value() === 0) {
    checkbox.click()
}
2
  • Thank you for your reply. I tried running this Java script in BetterTouchTool. But it not make any change. Any suggestions?
    – Eddy Perez
    Commented Nov 11, 2022 at 15:36
  • In BetterTouchTool, You can try to create an action "Run Real JavaScript", and change the "Source Type" to "Apple JavaScript for Automation", then paste the script.
    – zeewin
    Commented Nov 14, 2022 at 8:20
1

Here is a complete working script.

The previous answer posted on Nov 10, 2022 was not working for me. I don't know why it failed, but Apple might have changed the UI since that date.

This version integrates a corrected reference to the Voice Control checkbox. The reference was provided by Ron Reuter (here). This works for me under macOS Ventura, as of 2023-01-18.

do shell script "open -b com.apple.systempreferences " & ¬
    "/System/Library/PreferencePanes/UniversalAccessPref.prefPane"

tell application "System Events"
    tell its application process "System Settings"
        repeat until UI element 4 of group 1 of scroll area 1 of group 1 of ¬
            group 2 of splitter group 1 of group 1 of window "Accessibility" exists
            delay 0.1
        end repeat
        click UI element 1 of group 3 of scroll area 1 of group 1 of group 2 ¬
            of splitter group 1 of group 1 of window "Accessibility"
        repeat until checkbox "Voice Control" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control" exists
            delay 0.1
        end repeat
        click checkbox "Voice Control" of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window "Voice Control"
        
    end tell
end tell

tell application "System Settings" to quit
1
  • hi do you know how I can select the HDR setting of my external monitors only and enable it if it was off? apple.stackexchange.com/questions/454902/… i dont understand how to select the item using the group scroll syntax.
    – anarchy
    Commented Feb 15, 2023 at 6:55

You must log in to answer this question.

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