I have to admit: there is one killer-feature in Windows 7 that I absolutely admire. Maybe you even tried it yourself – hitting the windows key in combination with the arrow keys left and right will move the currently active window to the left/right of the monitor. Plus it will align that window so it precisely takes 50% of the screen’s width and 100% of its height. This is almost perfect if you find yourself working with two programs at the same time – working with a word processing tool while doing some research on a web page, for instance.
Being a Mac OS user myself, I was always jealous on the Win 7 version running within my VirtualBox. I wanted to have exactly that feature in Mac OS, so I decided to implement it. Fortunately, there is AppleScript. This tool allows us to script applications and to automate processes, yet with a quite strange syntax.
set screenWidth to 1280
set screenHeight to 800
set front_app to (path to frontmost application as Unicode text)
tell application front_app
set bounds of window 1 to {screenWidth / 2, 0, screenWidth, screenHeight}
end tell
Note that I have hardcoded the screen resolution for performance reasons. The rest of the script is pretty straight-forward: fetch the application which has the current focus and reset its bounds – starting at 50% of the width. The result is pretty neat:
Before:
After:
That’s exactly what I wanted to achieve. Now we would need exactly the same function to move a window to the left:
set bounds of window 1 to {0, 0, screenWidth / 2, screenHeight}
The last feature I wanted to implement is going full-screen (achievable in Windows by hitting Win+Up Arrow):
set bounds of window 1 to {0, 0, screenWidth, screenHeight}
If you work on a huge screen, you might even consider splitting it up horizontally. This could look like that:
Again, the code for achieving that target is pretty easy:
set tmp to get bounds of window 1
set bounds of window 1 to {item 1 of tmp, screenHeight / 2, item 3 of tmp, screenHeight}
Now I’d just need to assign hotkeys to my scripts in order to get more productive! For that task I used the fabulous app FastScripts. The lite version allows up to 10 assigned hotkeys, which is more than I’d need right now.
Unfortunately, there is one downside: if the programmers of the app haven’t implemented external scripting events, the script won’t work. This is the case for Preview and some other 3rd party apps. I found most of my day-to-day applications such as chrome, TextWranger and Skype working however. And the most important part – for me – Finder does work.