Skip to content

Instantly share code, notes, and snippets.

@toddwprice
Created July 22, 2020 15:25
Show Gist options
  • Save toddwprice/c44a87fd1f7cba612aa45fd5438a3472 to your computer and use it in GitHub Desktop.
Save toddwprice/c44a87fd1f7cba612aa45fd5438a3472 to your computer and use it in GitHub Desktop.
Hammerspoon for window management on macos
hs.hotkey.bind({"ctrl", "cmd"}, "up", 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)
hs.hotkey.bind({"ctrl", "cmd"}, "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)
hs.hotkey.bind({"ctrl", "cmd"}, "right", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
f.x = max.w / 2
f.y = max.y
f.w = max.w / 2
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind({"cmd", "ctrl"}, "down", function()
local win = hs.window.focusedWindow()
local f = win:frame()
local screen = win:screen()
local max = screen:frame()
local width = max.w / 1.618
local height = max.h / 1.618
-- f.x = (max.w - width) / 2
-- f.y = (max.h - height) / 2
f.x = 100
f.y = 100
f.w = width
f.h = height
win:setFrame(f)
end)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "left", function()
local win = hs.window.focusedWindow()
win:moveToScreen(win:screen():previous())
end)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "right", function()
local win = hs.window.focusedWindow()
win:moveToScreen(win:screen():next())
end)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "up", function()
local win = hs.window.focusedWindow()
win:moveToScreen(win:screen():previous())
end)
hs.hotkey.bind({"ctrl", "alt", "cmd"}, "down", function()
local win = hs.window.focusedWindow()
win:moveToScreen(win:screen():next())
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment