Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple window tiling with Hammerspoon
-- http://www.hammerspoon.org/go/
-- basic key shortcuts for window tiling
hs.window.animationDuration = 0
hs.hotkey.bind({"cmd", "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 - 4
f.y = max.y
f.w = max.w + 2
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind({"cmd", "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 - 4
f.y = max.y
f.w = max.w / 2 + 2
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind({"cmd", "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) - 2
f.y = max.y
f.w = max.w / 2 + 2
f.h = max.h
win:setFrame(f)
end)
hs.hotkey.bind({"cmd", "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)
hs.hotkey.bind({"cmd", "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) - 2
f.w = max.w
f.h = (max.h / 2) + 4
win:setFrame(f)
end)
--type-paste (for sites/apps that block actual-paste into password field)
hs.hotkey.bind({"cmd", "alt"}, "V", function()
hs.eventtap.keyStrokes(hs.pasteboard.getContents())
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment