I have a xojo app that I would like the user dynamically change the spoken language from one to another. In this case English to Italian and back. I am trying to navigate the panes of System Settings, and trying not to have to reboot the computer. Monkeybread has a solution, sort of, requiring Filemaker, which I don’t want to buy. Xojo will compile AppleScript. Every new operating system seems to change the System Settings pathway.
Any Ideas?
Is there a good resource that explains how to navigate the current System Settings? Older strategies don’t work.
Thanks!!!
Carl
PhysicsGuy, You didn’t indicate what OS you are running, but since you mentioned updating, I’ll assume you are on Sequoia. This script can select any available language listed in the languages pane. If you need to script adding the language as well you’ll have to wait a bit.
tell application "System Settings"
reveal pane "Language & Region"
end tell
General_LanguageAndRegion_outlineRow_Select(1)
delay 2
General_LanguageAndRegion_outlineRow_Select(2)
on General_LanguageAndRegion_outlineRow_Select(rowIndex)
tell application "System Events"
tell its application process "System Settings"
tell group 2 of splitter group 1 of group 1 of window 1
select row rowIndex of outline 1 of scroll area 1 of group 1 of scroll area 1 of group 1
end tell
end tell
end tell
end General_LanguageAndRegion_outlineRow_row
I had a some test with Xojo 2023. Xojo runtime can use very limited AppleScript functions.
Can use GUI Scripting functions?
No
Force Run AppleScript in Main Thread?
No
Can call AppleScript Libraries?
Yes
Can call AS Library including Frameworks?
No
Can get Script Path (that returned by path to me)?
Yes
Can call Generic Cocoa Functions?
Yes
Can use Cocoa system notification functions?
No
Can separate one script to multi by using script object?
Yes
Can scan modifier keys?
Yes
Can access internet?
Yes
Can call Address geocoder?
No
Greetings Paul,
Thanks for the quick reply.
Unfortunately, the script does not work. the error reads: System Events got an error: Can’t get scroll area 1 of group 1 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 of window 1 of application process “System Settings”. Invalid index.
When I add: do shell script “open x-apple.systempreferences:com.apple.Localization-Settings.extension”
I get all the way to Language & Region. The task is to switch the Preferred Languages from English to another language. (In my case, Italian) The purpose of the program is to speak the language correctly. Then when finished switch back.
It would be nice to select other languages other than the two in the panel, but is a job for later.
When I do this manually, a popup panel asks if I want to restart the computer. It seems this is not necessary to change the language.
Thanks again for your help.
Is there a decent reference that explains how to navigate the system settings? I’ve done a lot of looking. Much is out of date.
Very quick update:
I got this to work. So yes, what you did is great. Now I need to slide the Italian up to the first line and select no on the popup panel to restart. There is no hurry on this. If interested fine.
Thanks again!
Carl
Carl,
That Restart pop up is curious. Here, on Sequoia 15.2, selecting a different row in the preferred language outline changes the preferred language without any further user interaction required. Are you running this in a non-admin account? What OS version?
Here, running “General_LanguageAndRegion_outlineRow_Select(1)” selects English (US) and “General_LanguageAndRegion_outlineRow_Select(2)” Selects Francais. You may need to change the index numbers to match your languages.
Can you screenshot the Pop Up? If I can see it I can probably provide code to close it.
Greetings,
I’m on 15.2 using a macMini ~5 yo.
I have tried AppleScript and animator record, but nothing, literally.
Paul thanks for looking into this. This is not mission critical to my life, just a hobby writing software (mostly physics education stuff) since 1970.
Thanks again!!
Carl
Carl, I still can’t get that dialog to pop up, but this should address the buttons in it by their index. Just change the handler’s argument to match the appropriate button. I don’t know if the delay is necessary since I can’t get the dialog.
do shell script "open x-apple.systempreferences:com.apple.Localization-Settings.extension"
General_LanguageAndRegion_outlineRow_Select(2)
delay 3
General_LanguageAndRegion_Sheet1_Button_Click(2)
on General_LanguageAndRegion_outlineRow_Select(rowIndex)
tell application "System Events"
tell its application process "System Settings"
tell group 2 of splitter group 1 of group 1 of window 1
select row rowIndex of outline 1 of scroll area 1 of group 1 of scroll area 1 of group 1
end tell
end tell
end tell
end General_LanguageAndRegion_outlineRow_Select
on General_LanguageAndRegion_Sheet1_Button_Click(buttonIndex)
tell application "System Events"
tell its application process "System Settings"
tell button buttonIndex of sheet 1 of window 1
click
end tell
end tell
end tell
end General_LanguageAndRegion_Sheet1_Button
Hi Paul,
Thanks for the update. I imagine the reason why you do not see the popup panel is because you have to change the language of first choice at the top of the Language & Region sheet identified as Preferred Languages. To do this, I click and slide the second listed language, in this case Italian, up. Doing this affectuates the change. How to directly change without clicking and sliding is a mystery to me. It may be I have to select each language and remove them with the “-” button (not sure it’s a button) at the bottom of the Preferred Languages pane, and then “+” them back in the reverse order. To do this requires going into the region pulldown menu.
Yuck!
I was hoping there was a terminal command sequence, like the first one in the script that directly makes the necessary changes, or Script Editor record the process.
Thanks for your help. Have a great weekend,
Carl