Wishful Coding

Didn't you ever wish your
computer understood you?

AppleScript tiling windows

On Linux I use all sorts of key combos to tile windows, even though I no longer use a real tiling window manager.

On Mac OS X my windows are still mostly stacked and all over the place in a big mess. Mac doesn’t even have a proper fullscreen button, other than you know… making it a space on its own.

I know there are tools to do the same thing in a more fancy way, but instead I wrote a few AppleScripts to split and maximise windows.

To use them, I placed them in my Scripts folder and enabled the AppleScript menu in the preferences of the AppleScript Editor.

AppleScript Editor preferences

tell application "System Events"
	set frontmostProcess to first process where it is frontmost
	set visible of frontmostProcess to false
	repeat while (frontmostProcess is frontmost)
		delay 0.1
	end repeat
	set secondFrontmost to name of first process where it is frontmost
	set frontmost of frontmostProcess to true
	set frontmostApplication to name of frontmostProcess
end tell

tell application "Finder"
	set screenSize to bounds of window of desktop
	set screenWidth to item 3 of screenSize
	set screenHeight to item 4 of screenSize
end tell

tell application frontmostApplication
	set bounds of the first window to {0, 0, screenWidth / 2, screenHeight}
end tell

tell application secondFrontmost
	set bounds of the first window to {screenWidth / 2, 0, screenWidth, screenHeight}
end tell
tell application "System Events"
	set frontmostProcess to name of first process where it is frontmost
end tell

tell application "Finder"
	set screenSize to bounds of window of desktop
end tell

tell application frontmostProcess
	set bounds of the first window to screenSize
end tell
Published on