I was wondering if there's a way to select a specific system language with a SoundFlow Command? I'd like to use so to swap between English and Spanish.
What would be the best way to achieve this and how?
Thanks all!
- Christian Scheuer @chrscheuer2020-03-28 19:51:18.201Z
Hi Fernando
Just to make sure I understand the question - are you talking about the language displayed in menus etc. - or the input language on your keyboard?
Fernando J. Alanis @Fernando_J_Alanis
Oh sorry I wasn’t clear. I meant the input language from the keyboard (the little flag displayed on the menu bar).
Christian Scheuer @chrscheuer2020-03-28 22:07:17.917Z
Gotcha, thanks for the info. Edited the title now :)
SoundFlow doesn't have built in support for setting this (yet), so you may either wait for that, or use a third party tool.
For example you can use HomeBrew to install a utility called keyboardswitcher:
https://github.com/Lutzifer/keyboardSwitcher#installationTo install HomeBrew, run this in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Then to install the KeyboardSwitcher utility, run this in Terminal:
brew tap lutzifer/homebrew-tap brew install keyboardSwitcher
You can now run stuff like this to get the list of keyboards:
keyboardSwitcher list
And stuff like this to select the input language:
keyboardSwitcher select "U.S."
or
keyboardSwitcher select "Spanish"
Once you have this working in Terminal, you can then write a SoundFlow script that just runs those Terminal commands:
sf.system.exec({ commandLine: `keyboardSwitcher select "Spanish"` });
Fernando J. Alanis @Fernando_J_Alanis
I'm stuck installing the KeyboardSwitcher utility. Terminal shows this before finishing the install:
Last 15 lines from /Users/alanissound/Library/Logs/Homebrew/keyboardswitcher/01.xcodebuild:
2020-03-28 18:47:27 -0600
xcodebuild
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
If reporting this issue please do so at (not Homebrew/brew or Homebrew/core): https://github.com/lutzifer/homebrew-tap/issues
And apparently I can't install Xcode if I'm on Mojave...
Christian Scheuer @chrscheuer2020-03-29 19:01:01.148Z
Gotcha.. Yea installing Xcode sounds a bit overkill for this whole thing.
I think we should leave this question open to see if somebody has a simpler approach. The only real good approach IMO is if we include a new command for this in SF but that will take some time since we only just started on 3.6.
- In reply toFernando_J_Alanis⬆:Vladimir @poterukha
Also you can do it with AppleScript
Fernando J. Alanis @Fernando_J_Alanis
I believe this is the best way! I made two apps using this (one for each language), and set up SF just to launch the apps.
Thank you so much both Christian and Vladimir for your support!
Christian Scheuer @chrscheuer2020-03-30 10:44:24.716Z
Awesome.
Turns out SoundFlow can do this too directly:
const LANGUAGE = "Danish"; var textInputMenuItem = sf.ui.app('com.apple.systemuiserver').getElement("AXMenuBar").children.whoseDescription.is('text input').first; textInputMenuItem.elementClick(); textInputMenuItem.children.first.children.whoseTitle.is(LANGUAGE).first.elementClick();
Vladimir @poterukha
Hi, Christian!
I'm testing macOS 10.15.6 now on my main computer. Something is broken on the Apple side with this script. In SF I receive this error:
Logging error in action (01) ClickButtonAction: ClickButtonAction requires UIElement !! Command Error: ABC keyboard [user:-LG4yIqDk5zNxjDO-DWu:ck66f33aa0000sl10hf187cki]: ClickButtonAction requires UIElement (ABC keyboard: Line 5)
AppleScript version has also an errorCan you advise any workaround addressing this issue?
Christian Scheuer @chrscheuer2020-09-19 17:41:19.034Z
Yea I see the same - they apparently changed the structure.
This now works here on 10.15.6 for me:
const LANGUAGE = "ABC"; var textInputMenu = sf.ui.app('com.apple.TextInputMenuAgent').invalidate().getElement("AXExtrasMenuBar").children.filter(c => c.title.value === '')[0]; textInputMenu.elementClick({ asyncSwallow: true }); var subMenuItem = textInputMenu.children.first.children.whoseTitle.is(LANGUAGE).first.elementWaitFor().element; subMenuItem.elementClick();
Vladimir @poterukha
For me as well.
Thanks!- In reply tochrscheuer⬆:
Vladimir @poterukha
Christian, can you please help me with this script again? Apple changed the structure in Monterey, and the script doesn't work in macOS 12 and 13
Christian Scheuer @chrscheuer2023-05-02 01:15:54.913Z
I don't have time right now, unfortunately.
- In reply topoterukha⬆:
Fernando J. Alanis @Fernando_J_Alanis
Hey Vladimir,
I'm currently on MacOS 12, and this alternative works flawlessly.
I think it also works on MacOS 13.
Hope this is helpful!
Ben Rubin @Ben_Rubin
@Fernando_J_Alanis, how did you get the UI picker to pick the menu bar item? not working for me. Im also on Mac OS 12
Fernando J. Alanis @Fernando_J_Alanis
You're right!! I tried to make the macro again and it doesn't allow me to select that item.
Here's the code of that macro in case you want to try it out:
For English:
sf.ui.app("com.apple.TextInputMenuAgent").getElement("AXExtrasMenuBar").popupMenuSelect({ menuPath: ["U.S."], });
For Spanish:
sf.ui.app("com.apple.TextInputMenuAgent").getElement("AXExtrasMenuBar").popupMenuSelect({ menuPath: ["Spanish"], });