Skip to content

Instantly share code, notes, and snippets.

@joshmenden
Created November 27, 2020 17:06
Show Gist options
  • Save joshmenden/b0bfe15f8073afb0ce28ae1f2a6838c8 to your computer and use it in GitHub Desktop.
Save joshmenden/b0bfe15f8073afb0ce28ae1f2a6838c8 to your computer and use it in GitHub Desktop.
HammerspoonBounce
direction = "downright"
animate = false
hs.hotkey.bind({"cmd", "alt", "ctrl"}, "M", function()
animate = not animate
window = hs.window.focusedWindow()
width = hs.screen.primaryScreen():fullFrame().w
height = hs.screen.primaryScreen():fullFrame().h
hs.timer.doWhile(function() return animate end, function()
frame = window:frame()
if direction == "downright" then
if (frame.x + frame.w + 4) >= width then
direction = "downleft"
elseif (frame.y + frame.h + 4) >= height then
direction = "upright"
end
window:move(hs.geometry.point(4, 4))
elseif direction == "downleft" then
if (frame.x - 4) <= 0 then
direction = "downright"
elseif (frame.y + frame.h + 4) >= height then
direction = "upleft"
end
window:move(hs.geometry.point(-4, 4))
elseif direction == "upright" then
if (frame.x + frame.w + 4) >= width then
direction = "upleft"
elseif (frame.y - 4) <= 23 then
direction = "downright"
end
window:move(hs.geometry.point(4, -4))
elseif direction == "upleft" then
if (frame.x - 4) <= 0 then
direction = "upright"
elseif (frame.y - 27) <= 0 then
print("changing")
direction = "downleft"
end
window:move(hs.geometry.point(-4, -4))
end
end, 0.01)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment