Skip to content

Instantly share code, notes, and snippets.

@pc035860
Last active August 16, 2022 18:38
Show Gist options
  • Save pc035860/d162ab166a1e6801f2296cc518a078ae to your computer and use it in GitHub Desktop.
Save pc035860/d162ab166a1e6801f2296cc518a078ae to your computer and use it in GitHub Desktop.
Hammerspoon config on my M1 Mac mini
hs.application.enableSpotlightForNameSearches(true)
hyperKeys = {'cmd', 'alt', 'ctrl', 'shift'}
function bindHyperFocus(shortcutKey, findApplication)
hs.hotkey.bind(hyperKeys, shortcutKey, function()
-- hs.application.find(findApplication):activate()
hs.application.launchOrFocus(findApplication)
end)
end
function bindHyperLanuch(shortcutKey, findApplication)
hs.hotkey.bind(hyperKeys, shortcutKey, function()
hs.application.open(findApplication)
end)
end
bindHyperFocus('o', 'Opera')
bindHyperFocus('c', 'iTerm')
-- bindHyperFocus('s', 'sublime text')
bindHyperFocus('v', 'Visual Studio Code')
bindHyperFocus('p', 'Polymail')
bindHyperFocus('d', 'Dash')
bindHyperFocus('k', 'Slack')
bindHyperFocus('n', 'Notion')
bindHyperFocus('b', 'Google Chrome')
bindHyperFocus('y', 'WorkFlowy')
bindHyperFocus('t', 'Finder')
bindHyperFocus('m', 'Discord')
bindHyperLanuch('s', 'Sidecar-iPad')
hs.hotkey.bind(hyperKeys, 'r', function()
local win = hs.window.focusedWindow()
local f = win:frame()
local max = win:screen():frame()
local w = 1280
local h = 800
f.w = w
f.h = h
f.x = (max.w - w) / 2
f.y = (max.h - h) / 2
win:setFrame(f, 0)
end)
hs.hotkey.bind(hyperKeys, 'g', function()
local win = hs.window.focusedWindow()
local f = win:frame()
local max = win:screen():frame()
local w = max.w * 0.75
local h = max.h * 0.85
f.w = w
f.h = h
f.x = (max.w - w) / 2
f.y = (max.h - h) / 2
win:setFrame(f, 0)
end)
hs.hotkey.bind(hyperKeys, 'return', function ()
local win = hs.window.focusedWindow()
win:setFullscreen(not win:isFullscreen())
end)
-- in case you need to use hyper keys for media controls
function bindSystemKey(shortcutKey, systemKeyName)
hs.hotkey.bind(hyperKeys, shortcutKey, function()
hs.eventtap.event.newSystemKeyEvent(systemKeyName, true):post()
hs.eventtap.event.newSystemKeyEvent(systemKeyName, false):post()
end)
end
bindSystemKey('f7', 'PREVIOUS')
bindSystemKey('f8', 'PLAY')
bindSystemKey('f9', 'NEXT')
bindSystemKey('f10', 'MUTE')
bindSystemKey('f11', 'SOUND_DOWN')
bindSystemKey('f12', 'SOUND_UP')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment