Created
March 6, 2016 16:06
-
-
Save spadino/a62be95f7c3bbf53709d to your computer and use it in GitHub Desktop.
Move window to space at left or right just with keyboard, using hammer spoon. Complementing setup for KWM users.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Switch windows to next space at left or right | |
function moveWindowOneSpace(direction) | |
_mouseOrigin = hs.mouse.getAbsolutePosition() | |
local win = hs.window.focusedWindow() | |
_clickPoint = win:zoomButtonRect() | |
_clickPoint.x = _clickPoint.x + _clickPoint.w + 5 | |
_clickPoint.y = _clickPoint.y + (_clickPoint.h / 2) | |
local mouseClickEvent = hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftmousedown, _clickPoint) | |
mouseClickEvent:post() | |
hs.timer.usleep(150000) | |
local nextSpaceDownEvent = hs.eventtap.event.newKeyEvent({"ctrl"}, direction, true) | |
nextSpaceDownEvent:post() | |
end | |
function moveWindowOneSpaceEnd(direction) | |
local nextSpaceUpEvent = hs.eventtap.event.newKeyEvent({"ctrl"}, direction, false) | |
nextSpaceUpEvent:post() | |
hs.timer.usleep(150000) | |
local mouseReleaseEvent = hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftmouseup, _clickPoint) | |
mouseReleaseEvent:post() | |
hs.timer.usleep(100000) | |
hs.mouse.setAbsolutePosition(_mouseOrigin) | |
end | |
hk1 = hs.hotkey.bind({"ctrl","cmd"}, "right", | |
function() moveWindowOneSpace("right") end, | |
function() moveWindowOneSpaceEnd("right") end) | |
hk2 = hs.hotkey.bind({"ctrl","cmd"}, "left", | |
function() moveWindowOneSpace("left") end, | |
function() moveWindowOneSpaceEnd("left") end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working with Hammerspoon 0.9.45