Set up Windows 7 'Aero Snap' workalikes in OS X

Dec 17, '09 07:30:00AM

Contributed by: 23dos

You may know about the Aero Snap feature of Windows 7 which allows a user to "resize to half" a window by dragging it to the left or right side of the screen, or to maximize it by dragging it to the top edge of the screen (or by using shortcuts).

With a few AppleScripts and the shortcut manager Spark, you can get this feature in Mac OS X -- at least via shortcuts, though not by dragging to a screen edge.

First, save these AppleScripts somewhere on your hard drive. I'm actually a beginner with AppleScript, so these scripts may not be perfect, but they work.

left.scpt:

-- get Dock height
tell application "System Events" to tell process "Dock"
  set dock_dimensions to size in list 1
  set dock_height to item 2 of dock_dimensions
end tell
-- get the new width and height for the window
tell application "Finder"
  set desktop_dimensions to bounds of window of desktop
  set new_width to (item 3 of desktop_dimensions) / 2
  set new_height to (item 4 of desktop_dimensions) - dock_height
end tell
-- get active window
tell application "System Events"
  set frontApp to name of first application process whose frontmost is true
end tell
-- resize window
tell application frontApp
  activate
  set bounds of window 1 to {0, 0, new_width, new_height}
end tell
right.scpt:
-- get Dock height
tell application "System Events" to tell process "Dock"
  set dock_dimensions to size in list 1
  set dock_height to item 2 of dock_dimensions
end tell
-- get the new width and height for the window
tell application "Finder"
  set desktop_dimensions to bounds of window of desktop
  set new_width to (item 3 of desktop_dimensions) / 2
  set new_height to (item 4 of desktop_dimensions) - dock_height
end tell
-- get active window
tell application "System Events"
  set frontApp to name of first application process whose frontmost is true
end tell
-- resize window
tell application frontApp
  activate
  set bounds of window 1 to {new_width, 0, new_width * 2, new_height}
end tell
fullscreen.scpt:
-- get Dock height
tell application "System Events" to tell process "Dock"
  set dock_dimensions to size in list 1
  set dock_height to item 2 of dock_dimensions
end tell
-- get the new width and height for the window
tell application "Finder"
  set desktop_dimensions to bounds of window of desktop
  set new_width to (item 3 of desktop_dimensions) / 2
  set new_height to (item 4 of desktop_dimensions) - dock_height
end tell
-- get active window
tell application "System Events"
  set frontApp to name of first application process whose frontmost is true
end tell
-- resize window
tell application frontApp
  activate
  set bounds of window 1 to {0, 0, new_width * 2, new_height}
end tell
minimize.scpt:
-- get active window
tell application "System Events"
  set frontApp to name of first application process whose frontmost is true
end tell
-- minimize window
tell application frontApp
  activate
  set miniaturized of window 1 to true
end tell
Now install and open Spark to configure the global hotkeys to execute these AppleScripts. Click on the button on the upper left corner and choose AppleScript. Now you just have to click on File, choose the AppleScript you want to be executed, and choose the shortcut. I personally used these shortcuts, but you may choose anything you want: Also, don't forget to start Spark by clicking on Start Spark Daemon on the bottom of the program's window!

This works fine for almost all of my applications. iTunes behaves strangely with these AppleScripts, and it doesn't seem to work on Java applications either (Eclipse, Cyberduck). However, all other applications behave as expected.

I did this on Snow Leopard, but I guess it should work on Leopard as well.

[robg adds: I haven't tested this one.]

Comments (8)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20091208103758143