Tuesday, July 5, 2011

Resize and position windows with AppleScript


-- get the dimensions of the desktop, set up few variables
tell application "Finder"
set displayAreaDimensions to bounds of window of desktop
set x1 to item 1 of displayAreaDimensions
set y1 to item 2 of displayAreaDimensions
set x2 to item 3 of displayAreaDimensions
set y2 to item 4 of displayAreaDimensions
end tell

set width to x2 - x1
set height to y2 - y1

-- positioning iTunes, make it fullscreen
tell application "iTunes"
set the bounds of the first window to {x1, y1, x2, y2}
end tell

-- positioning Safari, halfwidth on the right
tell application "Safari"
set the bounds of the first window to {x1 + width / 2, y1, x2, y2}
end tell

-- positioning iTerm
tell application "iTerm"
set the bounds of the first window to {x1, y1, x1 + 1000, y1 + 600}
end tell

There are few useful blogposts about the topic.
www.ithug.com/2007/09/applescript-moving-and-resizing-windows or
www.ithug.com/2008/12/applescript-arranging-multiple-windows/

or you can use Divvy, which is an amazing window management app.

No comments:

Post a Comment