Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@clickysteve
Forked from prenagha/init.lua
Last active December 9, 2022 08:18
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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: https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907
-- Credit 2: https://gist.github.com/prenagha/1c28f71cb4d52b3133a4bff1b3849c3e
-- A global variable for the sub-key Hyper Mode
k = hs.hotkey.modal.new({}, '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
end)
end
-- Code to launch single apps that Alfred used to handle.
-- Hat-Tip: https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907
launch = function(appname)
hs.application.launchOrFocus(appname)
k.triggered = true
end
-- 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)
end
-- Enter Hyper Mode when F18 is pressed
pressedF18 = function()
k.triggered = false
k:enter()
end
-- Leave Hyper Mode when F18 is pressed,
-- send ESCAPE if no other keys are pressed.
releasedF18 = function()
k:exit()
if not k.triggered then
hs.eventtap.keyStroke({}, 'ESCAPE')
end
end
-- 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
end
end
if doReload then
hs.reload()
end
end
local myWatcher = hs.pathwatcher.new(os.getenv('HOME') .. '/.hammerspoon/', reloadConfig):start()
hs.alert.show('Config loaded')
@fatmcgav
Copy link

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

Any pointers on how I could combine it with https://github.com/miromannino/miro-windows-management/blob/master/position.lua?

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