briankendall / missionControlFullDesktopBar

Application for entering Mission Control with a full size desktop bar showing previews
The Unlicense
43 stars 2 forks source link

Hammerspoon alternative #4

Open Porco-Rosso opened 1 year ago

Porco-Rosso commented 1 year ago

Hi just want to note that you can do something similar with hammerspoon. It's also not 100% reliable because I couldn't figure out a proper way of using the timer delay function, but this seems to work 90% of the time.

-- Hyper+pageup Opens mission control with spaces visible. 
-- Still buggy, so doesn't work every time.
-- Would appreciate any help on getting sleep timers working.

hs.hotkey.bind({"ctrl", "alt", "cmd"},'pageup', function()
   local mousepoint = hs.mouse.absolutePosition()
   hs.mouse.absolutePosition({x=0,y=0})
   hs.eventtap.event.newKeyEvent('ctrl', true):post()
   hs.eventtap.event.newKeyEvent('up', true):post()
   hs.timer.usleep(30000)
   hs.mouse.absolutePosition({x=mousepoint.x,y=mousepoint.y})
   hs.eventtap.event.newKeyEvent('up', false):post()
   hs.eventtap.event.newKeyEvent('ctrl', false):post()
end)
briankendall commented 1 year ago

I actually made some experimental changes to MissionControlFullDesktopBar that added a third method, one that would reposition the mouse cursor, trigger mission control, and then put the cursor back to where it was before. After hours of working at it, though, I couldn't get it to work reliably, at least not without the entire process being agonizingly slow. The trouble was trying to figure out when the system had registered the mouse cursor as having moved, dealing with the fact that sometimes the cursor would not move after being told to, and figuring out how to move it back again taking into account possible movements by the user in the intervening time. I eventually abandoned it because the two methods I already have seem to work reliably enough.