Skip to content

Instantly share code, notes, and snippets.

@zhiyelee
Last active June 29, 2022 22:46
Show Gist options
  • Save zhiyelee/6a6983c1e1f4589a4796d1ffb28d6f8b to your computer and use it in GitHub Desktop.
Save zhiyelee/6a6983c1e1f4589a4796d1ffb28d6f8b to your computer and use it in GitHub Desktop.
hammerspoon: move cursor between screens and show a circle around the mouse
--- start move cursor bewteen screens
function show_circle()
local mousepoint = hs.mouse.getAbsolutePosition()
local color = {["red"]=0,["blue"]=1,["green"]=0,["alpha"]=0.5}
local circle = hs.drawing.circle(hs.geometry.rect(mousepoint.x - 40, mousepoint.y - 40, 80, 80))
circle:setStrokeColor(color)
circle:setFill(false)
circle:setStrokeWidth(5)
circle:bringToFront(true)
circle:show(0.5)
hs.timer.doAfter(0.8, function()
circle:delete()
end)
end
function move_cursor(direction)
return function()
local screen = hs.mouse.getCurrentScreen()
local nextScreen
if direction == "right" then
nextScreen = screen:next()
else
nextScreen = screen:previous()
end
local rect = nextScreen:fullFrame()
-- get the center of the rect
local center = hs.geometry.rect(rect).center
hs.mouse.setAbsolutePosition(center)
show_circle()
end
end
hs.hotkey.bind({"alt", "shift"}, "Right", move_cursor('right'))
hs.hotkey.bind({"alt", "shift"}, "Left", move_cursor('left'))
-- end move cursor between screens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment