No internet connection
  1. Home
  2. How to

How to Switch Input Language

By Fernando J. Alanis @Fernando_J_Alanis
    2020-03-28 00:05:22.791Z

    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!

    Solved in post #7, click to view
    • 16 replies
    1. 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?

      1. Oh sorry I wasn’t clear. I meant the input language from the keyboard (the little flag displayed on the menu bar).

        1. 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#installation

          To 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"` });
          
          1. 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...

            1. 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.

      2. Vladimir @poterukha
          2020-03-29 21:23:47.227Z

          Also you can do it with AppleScript

          Reply1 LikeSolution
          1. 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!

            1. 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();
              
              1. Vladimir @poterukha
                  2020-09-19 14:10:28.971Z

                  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 error

                  Can you advise any workaround addressing this issue?

                  1. 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();
                    
                    1. Vladimir @poterukha
                        2020-09-19 17:45:34.905Z

                        For me as well.
                        Thanks!

                        1. In reply tochrscheuer:
                          Vladimir @poterukha
                            2023-05-01 19:30:34.396Z

                            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

                            1. I don't have time right now, unfortunately.

                              1. In reply topoterukha:

                                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!

                                1. Ben Rubin @Ben_Rubin
                                    2023-05-07 01:53:14.539Z

                                    @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

                                    1. 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"],
                                      });