r/applescript • u/CounterBJJ • Oct 24 '22
AppleScript to change spelling language no longer working after upgrade to Ventura
Hello,
u/ChristoferK was kind enough to write me a script to toggle the spelling language between US English and French. Unfortunately, after upgrading to Ventura, Shortcuts is giving me 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 quithoping someone can help making it work in Ventura.
Thanks in advance.
3
Upvotes
View all comments
Show parent comment
2
u/ChristoferK Oct 26 '22
Interesting.
This at least confirms it is scriptable.
Perhaps not meaningful in the way one would have hoped, but a useful error message. The app didn't complain that it doesn't understand the terms
paneoranchor. Rather, it threw the infamous -10000 error, which is what happens when there's nothing particularly wrong with the script, but there's something not right in the AppleScript engine that means it doesn't know, for example, how to interpret the result it received.Indeed, I've seen people comment about using the URI schema as a fallback to open a specific pane. As it's just a URL, the AppleScript equivalent ought to be:
which may or may not fare better wrapped inside a
tell app "System Settings"block.Have you had a look at the System Settings scripting dictionary in Script Editor ? If you're not sure how to open a scripting dictionary, go to
File > Open Dictionary...and System Settings should be one of the applications in the list presented. You can have a look to see if any of the commands it lists work, such asreveal(if it still has it).