I often work with two or three windows side by side (a text editor and a terminal, a Finder window and a browser, etc.) and I like my windows to be neatly organised in space. I can of course move and resize windows with the mouse but it is both imprecise and tedious. I prefer keyboard shortcuts and the following details how I get them.
Up until now I was using the freeware TwoUp from Irradiated Software to move windows to the top, bottom, left, or right halves of the screen. But it has been discontinued and, although it still works, it is likely to break in the future. Its replacement, SizeUp, is a bit pricey for what it does, at $13.
I already had a script to maximise a window vertically which probably came from a modification of this Mac OS X Hint. It detects the display size using the technique published on Daring Fireball. I cleaned and modified this script and made a collection of them to move windows all around the desktop, while taking the Dock into account. They provide everything SizeUp provides:
- Top, bottom, left, right halves
- Upper right, lower right, lower left, upper left quarters
- Vertical maximisation
but also the ability to divide the screen vertically in three thirds, which is useful on larger screens.
I use those scripts within FastScripts to assign keyboard shortcuts to them. But they should work with any software that allows you to run AppleScripts based on keyboard shortcuts, such as Quicksilver, Butler or maybe even the Services menu starting from Snow Leopard. The shortcuts I use are:
Left ⌃⌥⌘← Left Third ⌃⌥← Right ⌃⌥⌘→ Right Third ⌃⌥→ Top ⌃⌥⌘↑ Upper Center Third ⌃⌥↑ Bottom ⌃⌥⌘↓ Lower Center Third ⌃⌥↓ Center Third (none) Upper Left ⌃⌥⇧← Lower Left ⌃⌥⇧↓ Maximize Vertically ⌃` Lower Right ⌃⌥⇧→ Upper Right ⌃⌥⇧↑
The source code is available on Github. I used text AppleScripts, not binary ones, because they are better for version tracking and because I prefer to use a regular text editor (TextMate in my case) rather than the dedicated AppleScript Editor.
The method used to detect the screen size is likely to give unexpected results when using multiple displays
The computations for windows positions and sizes only work when the Dock is positioned on the left of the screen, where it should be! ;)
The scripts do not work with some applications, most notably Apple’s own Preview.app
And probably many more…
Improvements are welcome!