mcpField
K
karabiner

karabiner

github.com/johnlindquist生産性2653 回インストール45 週間前に更新
リポジトリ

karabiner について

GokuRakuJoudoを使ってmacOSのキー割り当てを設定するスキルです。簡潔なEDNルールをKarabiner-ElementsのJSONに変換でき、条件付きショートカットやレイヤーを定義できます。

主な機能

  1. 01EDNルールをKarabiner JSONに変換
  2. 02修飾キーや条件付きのキー割り当て
  3. 03Simlayerとタップ/長押しレイヤー
  4. 04エイリアスとシェルテンプレートの再利用
  5. 05Gokuによる設定監視とサービス運用

活用シーン

  1. 01Caps LockをEscapeに割り当て
  2. 02アプリ別キーボードショートカットの設定
  3. 03Spaceキーでナビゲーションレイヤーを作成
  4. 04キーの組み合わせでシェルコマンドを実行

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/johnlindquist/claude --skill karabiner

インストール後、Claude Code で/karabinerを入力して読み込まれたか確認します。

同梱ファイルedn-reference.md

詳細

Karabiner(Goku 経由)

GokuRakuJoudoを使ってmacOSのキーボードのリマッピングを設定します。GokuRakuJoudoは、Karabiner-ElementsのJSONにコンパイルされるEDNベースのDSLです。

Gokuを使う理由

KarabinerのネイティブJSONは冗長です(20,000行以上)。GokuのEDN形式は10〜50倍簡潔です。

;; Goku: 1 line
[:caps_lock :escape]

;; Karabiner JSON: ~30 lines

前提条件

# Install Goku
brew install yqrashawn/goku/goku

# Start as service (watches ~/.config/karabiner.edn)
brew services start goku

# Or run once manually
goku

設定ファイルの場所:~/.config/karabiner.edn

ログ:~/Library/Logs/goku.log

EDN構文クイックリファレンス

基本構造
{:main [{:des "Rule description"
         :rules [[:from :to]
                 [:from2 :to2]]}]}
キーコード

すべてのキーはキーワード構文を使用します::a、:1、:f19、:spacebar、:return_or_enter

キーコードの確認方法:

  • Karabiner-EventViewer.appを実行します
  • keys_info.cljを参照します
修飾キーの構文
記号修飾キー例
!C左Command:!Ca = Cmd+A
!T左Control:!Ta = Ctrl+A
!O左Option:!Oa = Opt+A
!S左Shift:!Sa = Shift+A
!Q右Command:!Qa
!W右Control:!Wa
!E右Option:!Ea
!R右Shift:!Ra
!FFn:!Fa
!PCaps Lock:!Pa
!!Hyper(Cmd+Ctrl+Opt+Shift):!!a
##任意の修飾キー(省略可):##a

修飾キーの組み合わせ::!CTSa = Cmd+Ctrl+Shift+A

ルール形式
[:from :to]                           ;; Basic
[:from :to :condition]                ;; With condition
[:from :to :condition {:alone :x}]    ;; With options
複数のキー
;; Press sequence
[:a [:1 :2 :3]]           ;; a -> types 1, 2, 3

;; Simultaneous press (from)
[[:j :k] :escape]         ;; j+k together -> escape
シェルコマンド
[:!!1 "open -a Safari"]   ;; Hyper+1 runs shell command

条件

アプリケーション条件
{:applications {:chrome ["^com\\.google\\.Chrome$"]
                :code   ["com.microsoft.VSCode"]}
 :main [{:des "Chrome only"
         :rules [[:a :b :chrome]]}]}
デバイス条件
{:devices {:hhkb [{:vendor_id 1278 :product_id 51966}]}
 :main [{:rules [[:a :b :hhkb]]}]}
入力ソース条件
{:input-sources {:us {:input_source_id "com.apple.keylayout.US"}}
 :main [{:rules [[:a :b :us]]}]}
条件の組み合わせと否定
[:a :b [:chrome :hhkb]]    ;; Both conditions
[:a :b [:!chrome]]         ;; NOT in Chrome

レイヤー

Simlayer(推奨)

キーの同時押しをベースにした高速なレイヤーです。タイピング速度を重視する場合に最適です。

{:simlayers {:w-mode {:key :w}}        ;; Hold W activates layer
 :main [{:des "w-mode shortcuts"
         :rules [:w-mode                ;; Apply to this layer
                 [:e "open -a Finder"]  ;; W+E opens Finder
                 [:r "open -a Safari"]  ;; W+R opens Safari
                 ]}]}

Simlayerのオプション:

{:simlayers {:w-mode {:key :w
                      :modi {:mandatory [:left_control]}}}}  ;; Ctrl+W activates
標準レイヤー(タップ/ホールド)

タップ時とホールド時で動作を変えます。

{:layers {:caps-mode {:key :caps_lock
                      :alone {:key :escape}}}}  ;; Tap=Esc, Hold=layer
レイヤー変数の手動設定
;; Set variable on keydown, clear on keyup
[:w ["w-mode" 1] nil {:afterup ["w-mode" 0] :alone :w}]

;; Use the variable as condition
[:e :!Ce ["w-mode" 1]]  ;; W+E -> Cmd+E (only when w-mode=1)

テンプレート

再利用可能なシェルコマンドのパターンです。

{:templates {:open "open -a '%s'"
             :launch "/path/to/script.sh %s"
             :alfred "osascript -e 'tell application \"Alfred\" to run trigger \"%s\"'"}
 :main [{:rules [[:!!1 [:open "Safari"]]      ;; %s replaced with Safari
                 [:!!2 [:launch "arg1"]]]}]}

定義済みエイリアス

:froms(入力キー)
{:froms {:delete {:key :delete_or_backspace}
         :return {:key :return_or_enter}
         :mouse1 {:pkey :button1}}}
:tos(出力アクション)
{:tos {:spotlight {:key :spacebar :modi :command}
       :paste {:key :v :modi :command}
       :shift-click {:pkey :button1 :modi :left_shift}}}
カスタム修飾キーセット
{:modifiers {:hyper [:command :shift :control :option]
             :meh   [:shift :control :option]}}

高度なオプション

ルールの4番目の要素です。

[:from :to :condition {
  :alone :key              ;; to_if_alone
  :held :key               ;; to_if_held_down
  :afterup :key            ;; to_after_key_up
  :delayed {:invoked :x :canceled :y}
  :params {:alone_timeout 200}
}]

プロファイル設定

{:profiles {:Default {:default true
                      :sim 250        ;; Simultaneous threshold (ms)
                      :delay 500      ;; Delayed action time (ms)
                      :alone 1000     ;; to_if_alone timeout (ms)
                      :held 500}}}    ;; Held threshold (ms)

よくあるワークフロー

シンプルなリマッピングを追加する
{:main [{:des "Caps to Escape"
         :rules [[:caps_lock :escape]]}]}
アプリ固有のショートカットを追加する
{:applications {:chrome ["com.google.Chrome"]}
 :main [{:des "Chrome shortcuts"
         :rules [[:!Cl :!Ct :chrome]]}]}  ;; Cmd+L -> Cmd+T in Chrome
レイヤーを作成する
{:simlayers {:nav {:key :spacebar}}
 :main [{:des "Navigation layer"
         :rules [:nav
                 [:h :left_arrow]
                 [:j :down_arrow]
                 [:k :up_arrow]
                 [:l :right_arrow]]}]}
Hyperキーを設定する
{:main [{:des "Caps Lock to Hyper"
         :rules [[:caps_lock :!CTOSleft_shift nil {:alone :escape}]]}]}

CLIコマンド

goku           # Compile karabiner.edn once
gokuw          # Watch mode (compile on change)
goku -h        # Help

# Service management
brew services start goku    # Start watch service
brew services stop goku     # Stop service
brew services restart goku  # Restart after changes

# Check logs
tail -f ~/Library/Logs/goku.log

検証とデバッグ

  1. 構文を確認する:GokuがEDNの解析エラーを報告します
  2. 出力を確認する:~/.config/karabiner/karabiner.json
  3. EventViewerを使う:Karabiner-EventViewer.appにキーイベントが表示されます
  4. ログを確認する:tail ~/Library/Logs/goku.log

ベストプラクティス

  1. 頻繁に使うショートカットにはsimlayerを使います(hold-layerより高速です)
  2. 説明的な:desタグを使って、目的ごとにルールをグループ化します
  3. 繰り返し使うシェルコマンドのパターンにはテンプレートを使います
  4. 複雑なキー定義には、:froms/:tosでエイリアスを定義します
  5. 段階的にテストします。ルールを1つ追加して動作を確認し、これを繰り返します
  6. 大きな変更を行う前に、設定をバックアップします

リソース

コメント