Skip to content

Instantly share code, notes, and snippets.

@froi
Last active April 28, 2021 16:11
Show Gist options
  • Save froi/df2e5df19d9b79512f11 to your computer and use it in GitHub Desktop.
Save froi/df2e5df19d9b79512f11 to your computer and use it in GitHub Desktop.
Hammerspoon config
-- Streaming
hs.hotkey.bind({"alt", "ctrl"}, "S", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = 1920
f.h = 1080
win:setFrame(f)
end)
-- Fullscreen
hs.hotkey.bind({"alt", "ctrl"}, "F", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w
f.h = max.h
win:setFrame(f)
end)
-- Center
hs.hotkey.bind({"alt", "ctrl"}, "C", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 4)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
-- Bottom
hs.hotkey.bind({"alt", "ctrl"}, "Down", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = 0
f.y = max.y + (max.h / 2)
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end)
-- Top
hs.hotkey.bind({"alt", "ctrl"}, "Up", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = 0
f.y = 0
f.w = max.w
f.h = max.h / 2
win:setFrame(f)
end)
-- Left 50% width
hs.hotkey.bind({"alt", "ctrl"}, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
-- left, upper corner
hs.hotkey.bind({"alt", "ctrl"}, "Q", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x / 2
f.y = max.y / 2
f.w = max.w / 2
f.h = max.h / 2
win:setFrame(f)
end)
-- Left lower corner
hs.hotkey.bind({"alt", "ctrl"}, "Z", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x / 2
f.y = max.y + (max.h / 2)
f.w = max.w / 2
f.h = max.h / 2
win:setFrame(f)
end)
-- Right 50% screen width
hs.hotkey.bind({"alt", "ctrl"}, "Right", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
-- Right upper corner
hs.hotkey.bind({"alt", "ctrl"}, "P", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y / 2
f.w = max.w / 2
f.h = max.h / 2
win:setFrame(f)
end)
-- Right, lower corner
hs.hotkey.bind({"alt", "ctrl"}, "M", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.x + (max.w / 2)
f.y = max.y + (max.h / 2)
f.w = max.w / 2
f.h = max.h / 2
win:setFrame(f)
end)
-- Moving windows between screens
-- From: https://stackoverflow.com/a/58398311
function moveWindowToDisplay(d)
return function()
local displays = hs.screen.allScreens()
local win = hs.window.focusedWindow()
win:moveToScreen(displays[d], false, true)
end
end
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "1", moveWindowToDisplay(1))
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "2", moveWindowToDisplay(2))
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "3", moveWindowToDisplay(3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment