

These functions allow the movement of a specific window and also offer a convenience to simply move the focused window: - This function will move either the specified or the focuesd - window to the requested screen position function This.moveWindowToPosition(cell, window) if window = nil then window = hs.window.focusedWindow() end if window then local screen = window:screen() hs.t(window, cell, screen) end end - This function will move either the specified or the focused - window to the center of the sreen and let it fill up the - entire screen. The final part of the script merely contains two functions which move a window to a desired position. Let’s get started with building the grid: local This = This.screenPositions = screenPositions
#HAMMERSPOON TUTORIAL CODE#
The following code snippets all form a single file called a which will later be imported from a. This saves us the trouble of calculating the exact screen position every time and allows us to simply talk about parts of the screen. The code starts by using hs.grid to divide the screen into an easy to use grid. If you don’t want to do this, just assign other key-bindings to the functions.

If you want to use this as well, make sure you have followed my earlier post to setup a Hyper-key. Moving a windowīefore we begin, I’d like to note that the coming pieces of code bind the window-management functions to shortcuts using the Hyper-key. My most wanted key-combination at that time was a quick way to move a window from one monitor to the next.īy now, I have keys to maximise windows, put them in the left, right, top or bottom half of the screen and also for placing them in the top-left, top-right, bottom-left and bottom-right quarters of the screen. When I fell in love with Hammerspoon and created my Hyper key, window management was one of the first things I built with it. The folks behind Hammerspoon did that for you already! You could go the hardcore way and try to figure this out with ObjectiveC and the MacOS core docs, but that’s actually not necessary.
#HAMMERSPOON TUTORIAL SOFTWARE#
So, when you’re a software developer and the “right” tool doesn’t seem to exist, what do you do? You roll your own 😇.

The biggest problem for me is the fact that they occupy certain global key combinations and they’re not always willing to share or change those. Sadly, all of them seem to just miss the sweet spot of window management I’m looking for. I could obviously buy one of the tools available for this on the web, such as Magnet or BetterTouchTool. Now I need more fine-grained control over the position of each of my windows. I used to be happy with just being able to put two applications next to each either vertically or horizontally. With all these 4K/5K/8K screens on the market, window management is becoming more and more important. Window Management with Hammerspoon - Personal Productivity
