1 minute read

I recently made a video about how to make custom complex modifications in Karabiner-elements. Someone saw this video and reached out to me for some help.

It took me a few days, but I found a solution to his problem!

What didnโ€™t work

My first try looked something like this.

...
"from": {
    "key_code": "m",
        "modifiers": {
            "mandatory": ["command", "shift"]
        }
},
"to": [
    {
        "key_code": "5",
        "modifiers": {
            "mandatory": ["left_shift"]
        }
    },
    {
        "key_code": "period",
        "modifiers": {
            "mandatory": ["left_shift"]
        }
    },
    {
        "key_code": "5",
        "modifiers": {
            "mandatory": ["left_shift"]
        }
    }
],
...

โ€œThis should definitely work.โ€ I thought to myself. But it didnโ€™t.

Thankfully, I was smart enough to check out the logs and found this.

What did work

There is a simple reason why my previous solution didnโ€™t work.

Notice that for multiple arguments, the value of the modifiers key must be a list.

The error message tells us that for a single argument the value of the modifiers key must be a string!

We now have a simple fix by changing "mandatory": ["left_shift"] into "mandatory": "left_shift" and voila! We are done.

{
    "title": "Rstats pipe symbol (by @janmeppe)",
    "rules": [
        {
            "description": "Remaps shift + cmd + m to %>%",
            "manipulators": [
                {
                    "from": {
                        "key_code": "m",
                            "modifiers": {
                                "mandatory": ["command", "shift"]
                            }
                    },
                    "to": [
                        {
                            "key_code": "5",
                            "modifiers": {
                                "mandatory": "left_shift"
                            }
                        },
                        {
                            "key_code": "period",
                            "modifiers": {
                                "mandatory": "left_shift"
                            }
                        },
                        {
                            "key_code": "5",
                            "modifiers": {
                                "mandatory": "left_shift"
                            }
                        }
                    ],
                    "type": "basic"
                }
            ]
        }
    ]
}

Conclusion

In this blog post I show you how to create a custom complex modification in Karabiner-elements to remap shift + cmd + m to %>% which is the pipe symbol in R. Hopefully some Rstats people find this useful!

Also, remember to check your error logs!

Subscribe

Comments