Skip to content

Instantly share code, notes, and snippets.

Forked from prenagha/init.lua
Last active December 9, 2022 08:18
Show Gist options
  • Save clickysteve/e13a11b8fc9c963c08b3109d95bbacc5 to your computer and use it in GitHub Desktop.
Save clickysteve/e13a11b8fc9c963c08b3109d95bbacc5 to your computer and use it in GitHub Desktop.
Hammerspoon config file for getting Hyper Key (Caps) to work on Sierra
-- My own config file to get the Hyper Key working again with my current setup.
-- All credit goes to @prenagha and @ttscoff for their awesome original code that I tweaked for my own devices.
-- Credit 1:
-- Credit 2:
-- A global variable for the sub-key Hyper Mode
k ={}, 'F17')
-- Hyper-key for all the below are setup somewhere... Usually Keyboard Maestro or similar. Alfred doesn't handle them very well, so will set up separate bindings for individual apps below.
hyperBindings = {'c','m','a','b','d','e','f','g','h','i','j','k','l','m','n','p','q','r','t','1','2','3','4','5','6','7','8','9','0','d','g','s','f','TAB','v','b','O','-','s'}
for i,key in ipairs(hyperBindings) do
k:bind({}, key, nil, function() hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key)
k.triggered = true
-- Code to launch single apps that Alfred used to handle.
-- Hat-Tip:
launch = function(appname)
k.triggered = true
-- Keybinding for specific single apps.
singleapps = {
{'o', '1Password 6'},
for i, app in ipairs(singleapps) do
k:bind({}, app[1], function() launch(app[2]); k:exit(); end)
-- Enter Hyper Mode when F18 is pressed
pressedF18 = function()
k.triggered = false
-- Leave Hyper Mode when F18 is pressed,
-- send ESCAPE if no other keys are pressed.
releasedF18 = function()
if not k.triggered then
hs.eventtap.keyStroke({}, 'ESCAPE')
-- Bind the Hyper key
f19 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)
-- Reload config when any lua file in config directory changes, to save having to manually reload.
function reloadConfig(files)
doReload = false
for _,file in pairs(files) do
if file:sub(-4) == '.lua' then
doReload = true
if doReload then
local myWatcher ='HOME') .. '/.hammerspoon/', reloadConfig):start()'Config loaded')
Copy link

@clickysteve Cheers for the above code... works great...

Any pointers on how I could combine it with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment