5

I have a busted close-bracket key on my keyboard. Previously, I had used Karabiner to map L-control+open_bracket to close_bracket using a custom rule I wrote in the xml-format used by karabiner.

However, now that I've updated to Sierra, Karabiner is out, and Karabiner elements is in. Karabiner elements uses a JSON format. I tried to create a new rule and stick it in the JSON file:

"rules": [
         {"manipulators": [
                {"description": "bracket rule",
                        "from": {"key_code": "open_bracket", 
                                 "modifiers": ["left_control"]
                                },
                          "to": [{"key_code": "close_bracket",
                                  "modifiers":[]
                                }] 
                }         ]
         }]

However, this rule doesn't seem to work the way I'd like it to (it just maps open_bracket to close_bracket).

Does anyone have an insight into what I'm doing wrong here?

1
  • Have you contacted the developer of the application to ask for support?
    – fsb
    Commented Nov 25, 2017 at 16:41

2 Answers 2

10

Your sample appeared to be slightly different than other rules I've looked at. Here's a version that works for me:

file: map_lctl_plus_open_bracket_to_close_bracket.json :

{
  "title": "Map Lft-Ctl+Open-Bracket to Close-Bracket",
  "rules": [
    {
      "manipulators": [
        {
          "description": "bracket rule",
          "type": "basic",
          "from": {
            "key_code": "open_bracket",
            "modifiers": {
              "mandatory": [
                "left_control"
              ],
              "optional": [
                "caps_lock"
              ]
            }
          },
          "to": [
            {
              "key_code": "close_bracket"
            }
          ]
        }
      ]
    }
  ]
}

I wasn't able to determine any way to install the script other than through the "Import more rules from the internet" option, but I did figure out how to launch the importer on my own files.

Assuming you copy the file into /tmp/map_lctl_plus_open_bracket_to_close_bracket.json, pasting the following url into Safari should launch the importer:

karabiner://karabiner/assets/complex_modifications/import?url=file%3A%2F%2F%2Ftmp%2Fmap_lctl_plus_open_bracket_to_close_bracket.json

I have fully tested both the file content and the import url within this post, and all worked fine for me.

Good luck !


EDIT: Immediately after making this post, I think I found where the local filestore is for manually adding rules.

https://github.com/pqrs-org/KE-complex_modifications#local-testing

This is the github repo for the rules on the "Import more rules from the internet" page. It shows how to test the rules locally before submitting to the web repository.

TL;DR:

$ cp my_rule.json ~/.config/karabiner/assets/complex_modifications

The site also confirms the karabiner://... technique I mentioned above.

4
  • 1
    I find it much easier to edit Karabiner's JSON file directly at: ~/.config/karabiner/karabiner.json with TextEdit. If you make a mistake, Karabiner Elements will no longer show any scripts/modifications in its "Karabiner-Elements Preferences" window. S you can "debug" your changes/additions by watching this window while you save your text – and undo some steps … Commented Sep 29, 2018 at 15:10
  • 1
    You can also drop the JSON file in ~/.config/karabiner/assets/complex_modifications and it will appear in complex modifications when you press the add button. Commented May 14, 2019 at 18:20
  • 1
    OMFG how bad is the Karabiner-Elements doc?! "It will appear when you press the add button". Absolute gold. Now I've managed to import my simple little config without making a pull request to a GitHub repo. Thank you very much @DarrelHolt
    – NeilG
    Commented Feb 24, 2021 at 2:25
  • weirdly, I couldn't get it working by moving the file into the config directory (even though the correct directory was created by the app) but the karabiner:// method works.
    – Avi Cherry
    Commented Mar 19, 2022 at 1:25
1

Your own code simply leaves out the key word "mandatory" in combination with "left_control" – so Karabiner EACH time is content to register only "open_bracket" to remap the key to "close_bracket".

EDIT, … much later: you also need to code "type": "basic" in every manipulator !

Note: there is a complementary key word "optional" that may be default in lack of "mandatory"…

You must log in to answer this question.

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