Last active
February 17, 2019 01:57
-
-
Save al3xandru/bc5074fce216db2b271d14f988269967 to your computer and use it in GitHub Desktop.
Hammerspoon function for moving window to next desktop
This file contains hidden or 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
-- Move window to adjacent Desktop | |
-- direction param can be 'left' or 'right' | |
function moveWndNextSpace(direction) | |
local win = hs.window.focusedWindow() or hs.window.frontmostWindow() | |
if not win then | |
return | |
end | |
if not win:isStandard() then | |
return | |
end | |
if win:isFullScreen() then | |
return | |
end | |
local clickPoint = win:zoomButtonRect() | |
clickPoint.x = clickPoint.x + clickPoint.w + 5 | |
clickPoint.y = clickPoint.y + (clickPoint.h / 2) | |
hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseDown, clickPoint):post() | |
-- compacting these events seem to not trigger the change of desktop event | |
-- also according to https://www.hammerspoon.org/docs/hs.eventtap.event.html#newKeyEvent | |
-- this is the correct way to implement key events | |
hs.eventtap.event.newKeyEvent(hs.keycodes.map.ctrl, true):post() | |
hs.eventtap.event.newKeyEvent(direction, true):post() | |
hs.eventtap.event.newKeyEvent(direction, false):post() | |
hs.eventtap.event.newKeyEvent(hs.keycodes.map.ctrl, false):post() | |
hs.timer.doAfter(.5, function() | |
hs.eventtap.event.newMouseEvent(hs.eventtap.event.types.leftMouseUp, clickPoint):post() | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment