r/applescript • • 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 quit

hoping someone can help making it work in Ventura.

Thanks in advance.

3 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/CounterBJJ Oct 26 '22 edited Nov 05 '22

Hello,

Thank you for your continued input. Yes, the the app is now called System Settings, though its bundle identifier seems to be the same as

return the id of application "System Settings"

returns "com.apple.systempreferences"

Out of the three scriptability tests you provided, only the top one returns a meaningful result. By default, it opens the Appearances tab and returns {"Appearance"}.

If you click on another tab and run the script again, it returns that tab's name (ex: {"Keyboard"} for the keyboard tab).

The other two scripts produce the same error message:

error "System Settings got an error: AppleEvent handler failed." number -10000.

I guess I will have to be patient and see if meaningful solutions are found in the following weeks and months.

EDIT: I did some research and found that the keyboard pane id in Ventura is <com.apple.Keyboard-Settings.extension>. It can be opened in Terminal with

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

2

u/ChristoferK Oct 26 '22
return the id of application "System Settings"

returns "com.apple.systempreferences"

Interesting.

Out of the three scriptability tests you provided, only the top one returns a meaningful result. By default, it opens the Appearances tab and returns {"Appearance"}.

This at least confirms it is scriptable.

error "System Settings got an error: AppleEvent handler failed." number -10000.

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 pane or anchor. 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.

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

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:

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

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 as reveal (if it still has it).