An Applescript to match window heights and positions

Dec 10, '03 09:52:00AM

Contributed by: Anonymous

I really liked GaryA's hint on getting Exposé to spread out an app's windows in a line, so I wrote a little AppleScript to arrange them as necessary automatically. It makes the rest of the app's windows match the height and vertical position of the frontmost window. You have to hard-code which application to run this with, though, as I couldn't figure out how to get an AppleScript to simply affect whatever app happens to be in the front.


tell application "Microsoft Word"
  set winrect to bounds of 1st window
  set x to 1st item in winrect
  set y to 2nd item in winrect
  set w to (3rd item in winrect) - x
  set h to (4th item in winrect) - y
  set winlist to every window
   
  repeat with curwin in every item in winlist
    tell curwin
      set currect to bounds of curwin
      set curx to 1st item in currect
      set cury to 2nd item in currect
      set curw to (3rd item in currect) - curx
      set curh to (4th item in currect) - cury
      -- swap the commenting of the next two lines
      -- if you want horizontals to match too
      set bounds of curwin to {curx, y, curx + curw, y + h}
      --set bounds of curwin to {x, y, x + w, y + h}
    end tell
              
  end repeat
end tell
Note: if you have multiple displays, you'll need to swap the comments on the set lines as indicated in the script, or it could possibly position windows completely off of any display ... this will make it match horizontal position & size as well.

Comments (9)


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