-1

Good day to you all,

I used to switch between 3 languages (Korean, English, German) while pressing ctrl+space (select the previous input source in mac keyboard setting) which is really annoying. Then I found Karabiner-Elements and use it on Mac m1 pro since a few weeks but there is an issue for users who use the language Chinese, Japanese, Korean, and Vietnamese (cjkv)

(Check these links referring to the issue:

https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/to/select-input-source/

https://github.com/pqrs-org/Karabiner-Elements/issues/1602

https://github.com/pqrs-org/Karabiner-Elements/issues/3103)

The issue is that the menubar shows that I am using Korean but if I type, the result is the previous language. Let's say: If I am using German and switch to Korean by pressing a certain key combination, the menubar says it is changed to Korean but the keyboard layout is still German.

It does not happen always but when it happens, I have to press ctrl + space twice to go (from Korean to German) and (from German to Korean) again. Then I can use a Korean keyboard layout. That is my current workaround.

Now I managed to make my own complex modification code for Karabiner-Elements. I use

  • right command to switch to English

  • right shift to switch to German

  • right option to switch to Korean.

But I want to code json file like this: If I press on right option to switch to Korean, ctrl + space combination gets pressed twice automatically so that the workaround happens automatically without me having to press ctrl + space twice by myself.

Is this even possible to code a json file like that?

Below, you will see my Command-Launching.json file:

{
    "title": "private setting for language etc.",
    "rules": [
  
        { "description": "Right Command to US", 
          "manipulators": [ 
            { 
                "from": { 
                    "key_code": "right_command", "modifiers": { 
                        "optional": [
                             "any" 
                             ] 
                    } 
                }, "to": [ 
                    { "key_code": "right_command", "lazy": true } 
                ], 
                "to_if_alone": [ 
                    { "select_input_source": { "language": "en" } } 
                ], 
                "type": "basic" 
            }
        ] 
        }, 
        
        {   "description": "Right Shift to DE", 
            "manipulators": [ 
                { "from": { 
                    "key_code": "right_shift", "modifiers": 
                    { "optional": [ 
                        "any" 
                        ] 
                    } 
                }, "to": [ 
                { "key_code": "right_shift", "lazy": true } 
                ], 
                "to_if_alone": [ 
                    { "select_input_source": { "language": "de" } } 
                ], 
                    "type": "basic" 
                } 
            ] 
        },
        
        {   "description": "Right Option to KO", 
            "manipulators": [ 
                { "from": { 
                    "key_code": "right_option", 
                    "modifiers": 
                    { "optional": [ 
                        "any" 
                        ] 
                    } 
                }, "to": [ 
                { "key_code": "right_option", "lazy": true } 
                ], 
                "to_if_alone": [ 
                    { "select_input_source": { "language": "ko" } } 
                ], 
                    "type": "basic" 
                }
            ] 
        }
    ]
}

Best regards

I tried to find if-else condition statement but nothing really helped.

1 Answers1

1

I found out that it is impossible to modify directly in "command-launching.json" as I wish according to the Karabiner-Elements documentation.

There is another workaround. Instead of using "repeat": 2 in the command to_if_alone, follow the steps:

  1. Create a shell script, let's call it run_command_twice.sh, and put it in a known location (like your home directory):

     #!/bin/bash
     osascript -e 'delay 0.01' -e 'tell application "System Events" to keystroke (key code 49 using control down)'
     osascript -e 'delay 0.01' -e 'tell application "System Events" to keystroke (key code 49 using control down)'
    
  2. Make sure to give execute permissions to your script:

    chmod +x ~/run_command_twice.sh
    
  3. Then modify your command-launching.json to call this script:

    {
      ...
      "to_if_alone": [
        {
          "shell_command": "~/run_command_twice.sh"
        }
      ],
      ...
    }
    

NOTES:

  1. This way, when you press the right_option key alone, it will call the shell script which in turn will run the osascript command twice.
  2. Remember to replace ~/run_command_twice.sh with the actual path to your script.
  • Please note that it has a bit delay in comparison to using the shortcut, set in the mac setting, to switch to the previous language since Karabiner cannot directly replicate the system-level behavior. It is just a tool that allows customization and remapping of key events. – AskingThings May 31 '23 at 12:16