Skip to content

Instantly share code, notes, and snippets.

@clickysteve clickysteve/init.lua forked from prenagha/init.lua
Last active Aug 10, 2018

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Feb 28, 2017

@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
You can’t perform that action at this time.