Sunday, December 4, 2022

#1 2022-11-02 03:14:48 pm

80sTherapy
Member
Registered: 2021-03-25
Posts: 5

AppleScript to toggle spelling language not working on Ventura

A Redditor was kind enough to write me a script to toggle the spelling language between US English and French. Unfortunately, after upgrading to Ventura, running the script produces the following error message:

System Settings got an error: AppleEvent handler failed.

The script is:

property language : {en_us:"U.S. English", fr:"Français", auto:"Automatic By Language", default:a reference to my language's fr, alternate:a reference to my language's en_us}

property toggle : contents of my language's {default, alternate}

to wait for _UIElement
    tell application id ("com.apple.systemevents") ¬
        to repeat 20 times -- 10 seconds
        if the _UIElement exists then return
        delay 0.5
    end repeat
   
    error "Timeout." from _UIElement
end wait


tell application id "com.apple.systempreferences" to reveal ¬
    anchor "Text" of pane id "com.apple.preference.keyboard"


tell application id ("com.apple.systemevents") to tell (process 1 ¬
    where its bundle identifier = "com.apple.systempreferences") ¬
    to tell the front window to tell (a reference to tab group 1's ¬
    pop up button 3)
    my (wait for it)
    click it
    set bool to 1 - ((the value = toggle's item 1) as integer) * 2
    tell (a reference to menu 1)
        my (wait for it)
        pick the menu item named (toggle's item index bool)
    end tell
    log the value as text
end tell


tell application id "com.apple.systempreferences" to quit


I am not a coder, but after doing some research, I have found that the following command opens the "Keyboard" pane in System Settings.

open location "x-apple.systempreferences:com.apple.Keyboard-Settings.extension"

That's about as far as I've gotten...

I hope someone can help making it work in Ventura. Thanks in advance for any assistance you can provide.

Last edited by 80sTherapy (2022-11-02 03:16:41 pm)

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)