Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move an application between monitors in Hammerspoon?

Tags:

hammerspoon

At work I have a 3 monitor setup. I would like to move the current application to a second or a third monitor with a key binding. How to do that?

like image 678
paulinhorocha Avatar asked Jan 11 '19 17:01

paulinhorocha


People also ask

How do I drag my screen to my third monitor?

If you right click on your desktop and open up display settings, you'll see your three monitors listed. You can drag and drop the squares in the order you'd like.


1 Answers

I use the following script to cycle the focused window through the screens.

-- bind hotkey
hs.hotkey.bind({'alt', 'ctrl', 'cmd'}, 'n', function()
  -- get the focused window
  local win = hs.window.focusedWindow()
  -- get the screen where the focused window is displayed, a.k.a. current screen
  local screen = win:screen()
  -- compute the unitRect of the focused window relative to the current screen
  -- and move the window to the next screen setting the same unitRect 
  win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0)
end)
like image 75
Lukas Avatar answered Oct 03 '22 07:10

Lukas