3

Objective

This is more about to confirm if this configuration is correct to do remapping with Karabiner-Elements to remap:

  • caps_lock to left_control if it is in Terminal
  • caps_lock to left_control if it is in Emacs
  • caps_lock to left_command otherwise

Appreciate if someone can confirm if this is good enough, or suggest better/correct ways.

Background

Looking for a way to remap keys in Mac Sierra and found Karabiner-Elements for the purpose, but not many examples and documentations about the syntax of karabiner.json. Hence looking for inputs.

Code

"complex_modifications": {
    "parameters": {
        "basic.to_if_alone_timeout_milliseconds": 1000
    },
    "rules": [
        {
            "manipulators": [
                {
                    "description": "Change caps_lock to left_command in Terminal.",
                    "conditions": [
                        {
                            "bundle_identifiers": [
                                "^com\\.apple\\.Terminal$",
                                "^com\\.googlecode\\.iterm2$",
                                "^co\\.zeit\\.hyperterm$",
                                "^co\\.zeit\\.hyper$"
                            ],
                            "type": "frontmost_application_if"
                        }
                    ],
                    "from": {
                        "key_code": "caps_lock",
                        "modifiers": {
                            "optional": [
                                "any"
                            ]
                        }
                    },
                    "to": [
                        {
                            "key_code": "left_control"
                        }
                    ],
                    "type": "basic"
                }
            ]
        },
        {
            "description": "caps_lock to left_control in Emacs",
            "manipulators": [
                {
                    "conditions": [
                        {
                            "bundle_identifiers": [
                                "org\\.gnu\\.Emacs"
                            ],
                            "type": "frontmost_application_if"
                        }
                    ],
                    "from": {
                        "key_code": "caps_lock",
                        "modifiers": {
                            "optional": [
                                "any"
                            ]
                        }
                    },
                    "to": [
                        {
                            "key_code": "left_control"
                        }
                    ],
                    "type": "basic"
                }
            ]
        },
        {
            "description": "caps_lock to left_command otherwise",
            "manipulators": [
                {
                    "from": {
                        "key_code": "caps_lock",
                        "modifiers": {
                            "optional": [
                                "any"
                            ]
                        }
                    },
                    "to": [
                        {
                            "key_code": "left_command"
                        }
                    ],
                    "type": "basic"
                }
            ]
        }
    ]
}

2 Answers 2

1

Appreciate if someone can confirm if this is good enough, or suggest better/correct ways.

Using goku, for remapping Caps Lock ⇪ to Left ⌃ if it is in Terminal, Emacs and to Left ⌘ otherwise, use these three strings:

[:caps_lock :left_control :emacs]
[:caps_lock :left_control :terminal]
[:caps_lock :left_command]

Assuming you predefined :emacs & :terminal in the :applications {} section above:

:applications {
    :emacs ["org.gnu.Emacs"]
    :terminal ["com.apple.Terminal"]
}

If you’re using Karabiner only, the settings will be:

{
    "description" : "Caps Lock",
    "manipulators" : [ {
        "from" : {
            "key_code" : "caps_lock"
        },
        "to" : [ {
            "key_code" : "left_control"
        } ],
        "conditions" : [ {
            "type" : "frontmost_application_if",
            "bundle_identifiers" : ["org.gnu.Emacs"]
        } ],
        "type" : "basic"
    }, {
        "from" : {
            "key_code" : "caps_lock"
        },
        "to" : [ {
            "key_code" : "left_control"
        } ],
        "conditions" : [ {
            "type" : "frontmost_application_if",
            "bundle_identifiers" : ["com.apple.Terminal"]
        } ],
        "type" : "basic"
    }, {
        "from" : {
            "key_code" : "caps_lock"
        },
        "to" : [ {
            "key_code" : "left_command"
        } ],
        "type" : "basic"
    } ]
}
-1

Share my configuration:

{
  "title": "Function key if",
  "rules": [
    {
      "description": "Function key if",
      "manipulators": [
        {
          "from": {
            "key_code": "delete_forward"
          },
          "to": [
            {
            "key_code": "p",
            "modifiers": "left_command"
            }
          ],
          "conditions": [{
            "type": "frontmost_application_if",
            "bundle_identifiers": ["^com\\.microsoft\\.VSCode$"] }],
          "type": "basic"
        },
        {
          "from": {
            "key_code": "delete_forward"
          },
          "to": [
            {
            "key_code": "i",
            "modifiers": ["left_command","left_option"]
            }
          ],
          "conditions": [{
            "type": "frontmost_application_if",
            "bundle_identifiers": ["^com\\.google\\.Chrome$"] }],
          "type": "basic"
        }
      ]
    }
  ]
}


1
  • 1
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 11, 2022 at 14:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .