Skip to content

Instantly share code, notes, and snippets.

@saneef
Last active June 2, 2022 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saneef/b0b2aed598f17764e6d5c5040925fbe5 to your computer and use it in GitHub Desktop.
Save saneef/b0b2aed598f17764e6d5c5040925fbe5 to your computer and use it in GitHub Desktop.
Karabiner config
{;; applciations can be used as a condition, where the key maps
;; only works in those apps
:applications {:apps-for-emacs-movements ["^md\\.obsidian$"
"^org\\.mozilla\\.firefox$"
"^com\\.tinyspeck\\.slackmacgap$"]}
;; with tos you can predefine 'to' keypresses to easily parse them
:tos {;; in order for OSX to register a caps lock press, it has to be held for a little under 100ms
:press_escape {:key :escape :hold_down_ms 100}}
:main [{:des "Override caps lock"
:rules [;;Caps lock to Escape on single press, Control on hold
[:##caps_lock ;; FROM caps lock with no or any modifiers
:left_control ;; TO left control
nil ;; with no conditionals
{:alone :press_escape} ;; OPTIONS: if pressed alone, press escape, but hold it for 100ms
]]}
{:des "Control p/n to up/down on Obsidian"
:rules [[:!Tp :up_arrow :apps-for-emacs-movements]
[:!Tn :down_arrow :apps-for-emacs-movements]]}
{:des "Quit application by pressing command-q twice"
:rules [[:!Cq :!Cq ["command-q" 1]]
[:!Cq
[[:noti :cmdq "Press ⌘-q again to Quit"] ["command-q" 1]]
nil
{:delayed {:invoked [[:noti :cmdq] ["command-q" 0]]
:canceled [[:noti :cmdq] ["command-q" 0]]}
:params {:delay 700}}]]}]}
;; References
;; https://gist.github.com/nikolai-cc/02f6b070972840323ae355ef847e91a6
;; ! | means mandatory
;; # | means optional
;; C | left_command
;; T | left_control
;; O | left_option
;; S | left_shift
;; F | fn
;; Q | right_command
;; W | right_control
;; E | right_option
;; R | right_shift
;; P | caps_lock
;; !! | mandatory command + control + optional + shift (hyper)
;; ## | optional any
{
"global" : {
"check_for_updates_on_startup" : true,
"show_in_menu_bar" : true,
"show_profile_name_in_menu_bar" : false
},
"profiles" : [ {
"complex_modifications" : {
"parameters" : {
"basic.simultaneous_threshold_milliseconds" : 50,
"basic.to_delayed_action_delay_milliseconds" : 500,
"basic.to_if_alone_timeout_milliseconds" : 1000,
"basic.to_if_held_down_threshold_milliseconds" : 500
},
"rules" : [ {
"description" : "Override caps lock",
"manipulators" : [ {
"to_if_alone" : [ {
"key_code" : "escape",
"hold_down_milliseconds" : 100
} ],
"from" : {
"key_code" : "caps_lock",
"modifiers" : {
"optional" : [ "any" ]
}
},
"to" : [ {
"key_code" : "left_control"
} ],
"type" : "basic"
} ]
}, {
"description" : "Control p/n to up/down on Obsidian",
"manipulators" : [ {
"from" : {
"key_code" : "p",
"modifiers" : {
"mandatory" : [ "left_control" ]
}
},
"to" : [ {
"key_code" : "up_arrow"
} ],
"conditions" : [ {
"type" : "frontmost_application_if",
"bundle_identifiers" : [ "^md\\.obsidian$", "^org\\.mozilla\\.firefox$", "^com\\.tinyspeck\\.slackmacgap$" ]
} ],
"type" : "basic"
}, {
"from" : {
"key_code" : "n",
"modifiers" : {
"mandatory" : [ "left_control" ]
}
},
"to" : [ {
"key_code" : "down_arrow"
} ],
"conditions" : [ {
"type" : "frontmost_application_if",
"bundle_identifiers" : [ "^md\\.obsidian$", "^org\\.mozilla\\.firefox$", "^com\\.tinyspeck\\.slackmacgap$" ]
} ],
"type" : "basic"
} ]
}, {
"description" : "Quit application by pressing command-q twice",
"manipulators" : [ {
"from" : {
"key_code" : "q",
"modifiers" : {
"mandatory" : [ "left_command" ]
}
},
"to" : [ {
"key_code" : "q",
"modifiers" : [ "left_command" ]
} ],
"conditions" : [ {
"name" : "command-q",
"value" : 1,
"type" : "variable_if"
} ],
"type" : "basic"
}, {
"to_delayed_action" : {
"to_if_invoked" : [ {
"set_notification_message" : {
"id" : "cmdq",
"text" : ""
}
}, {
"set_variable" : {
"name" : "command-q",
"value" : 0
}
} ],
"to_if_canceled" : [ {
"set_notification_message" : {
"id" : "cmdq",
"text" : ""
}
}, {
"set_variable" : {
"name" : "command-q",
"value" : 0
}
} ]
},
"parameters" : {
"basic.to_delayed_action_delay_milliseconds" : 700
},
"from" : {
"key_code" : "q",
"modifiers" : {
"mandatory" : [ "left_command" ]
}
},
"to" : [ {
"set_notification_message" : {
"id" : "cmdq",
"text" : "Press ⌘-q again to Quit"
}
}, {
"set_variable" : {
"name" : "command-q",
"value" : 1
}
} ],
"type" : "basic"
} ]
} ]
},
"devices" : [ ],
"fn_function_keys" : [ {
"from" : {
"key_code" : "f1"
},
"to" : [ {
"apple_vendor_keyboard_key_code" : "brightness_down"
} ]
}, {
"from" : {
"key_code" : "f2"
},
"to" : [ {
"apple_vendor_keyboard_key_code" : "brightness_up"
} ]
}, {
"from" : {
"key_code" : "f3"
},
"to" : [ {
"apple_vendor_keyboard_key_code" : "mission_control"
} ]
}, {
"from" : {
"key_code" : "f4"
},
"to" : [ {
"apple_vendor_keyboard_key_code" : "spotlight"
} ]
}, {
"from" : {
"key_code" : "f5"
},
"to" : [ {
"consumer_key_code" : "dictation"
} ]
}, {
"from" : {
"key_code" : "f6"
},
"to" : [ {
"key_code" : "f6"
} ]
}, {
"from" : {
"key_code" : "f7"
},
"to" : [ {
"consumer_key_code" : "rewind"
} ]
}, {
"from" : {
"key_code" : "f8"
},
"to" : [ {
"consumer_key_code" : "play_or_pause"
} ]
}, {
"from" : {
"key_code" : "f9"
},
"to" : [ {
"consumer_key_code" : "fast_forward"
} ]
}, {
"from" : {
"key_code" : "f10"
},
"to" : [ {
"consumer_key_code" : "mute"
} ]
}, {
"from" : {
"key_code" : "f11"
},
"to" : [ {
"consumer_key_code" : "volume_decrement"
} ]
}, {
"from" : {
"key_code" : "f12"
},
"to" : [ {
"consumer_key_code" : "volume_increment"
} ]
} ],
"name" : "Default",
"parameters" : {
"delay_milliseconds_before_open_device" : 1000
},
"selected" : true,
"simple_modifications" : [ ],
"virtual_hid_keyboard" : {
"country_code" : 0,
"indicate_sticky_modifier_keys_state" : true,
"mouse_key_xy_scale" : 100
}
} ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment