3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Karabiner-Elementsでターミナルのショートカットを無効化する

Posted at

環境

  • macOS 10.14 (Mojave)
  • ターミナルアプリ 2.9.5

問題

USキーボードを使っているので,Karabiner-Elementsを使いこちらのComplex Modificationsを使って⌘キーの単発入力を英数・かなキーに入れ替えているのですが,英数・かな切り替えのために⌘キーを押したときに,次のキータイプが被ってしまい,ターミナルの⌘ショートカットが間違って発動してしまう問題に悩んでいました.

特によく間違って発動するのが⌘T(新規タブ),⌘D(ペインの分割),⌘W(ウィンドウを閉じる)だったので,これらを無効化するComplex Modificationsを作成しました.

手順

新しいComplex Modificationsの作成

以下のファイルを$HOME/.config/karabiner/assets/complex_modifications/に作成します.

terminal-disable-shortcut.json
{
  "title": "ターミナル設定",
  "rules": [
    {
      "description": "⌘T(新規タブ)の無効化",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "t",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "caps_lock"
              ]
            }
          },
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "^com\\.apple\\.Terminal$"
              ]
            }
          ]
        }
      ]
    },
    {
      "description": "⌘D(ペインの分割)の無効化",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "d",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "caps_lock"
              ]
            }
          },
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "^com\\.apple\\.Terminal$"
              ]
            }
          ]
        }
      ]
    },
    {
      "description": "⌘W(ウィンドウを閉じる)の無効化",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "w",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "caps_lock"
              ]
            }
          },
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "^com\\.apple\\.Terminal$"
              ]
            }
          ]
        }
      ]
    }
  ]
}

Karabiner-ElementsでComplex Modificationsの追加

上記ファイルを作成すると,Karabiner-ElementsのComplex ModificaitonsタブでAdd ruleした際に,追加した3つのルールがインポートできるようになっているので,これらをインポートします.

ke-cm-list.png ke-cm-add-rule.png ke-cm-list2.png

ターミナルアプリで確認

ターミナルアプリで⌘T,⌘D,⌘Wを押しても何も反応しなくなっている(無効化)されているはずです.

注意

今回のルールはターミナルアプリに対する3つのショートカット(⌘T,⌘D,⌘W)しか無効化していないので,iTermなど他のアプリを使っている場合や,他のショートカットを無効化したい場合は,terminal-disable-shortcut.jsonを修正する必要があります.(キーコードとアプリのBundle Identifierくらいなので,見ればなんとなくわかると思います.)

課題

ショートカットの誤作動はこれで防げそうですが,ショートカットを潰すという回避策でしかないので,本当は自作キーボードで英数・かなキー付きの半USキーボードなんか作りたいですね・・・(MacBookだとどうしようもないけど.)

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?