window size follow up

so inspired was i by hacking window positions, i thought some more moving things around was in order. two more examples for you to all play with.

first, this little chap will move the top focused window to the top left hand corner of your screen. gosh, isn't that fun

--first get name of top most app
tell application "System Events" to set appList to name of application
    processes whose frontmost is true
set frontApp to item 1 of appList

--get size of the window we're going to move
tell application "System Events" to tell process frontApp
        to set {winWidth, winHeight} to size of front window

--move the window
tell application frontApp to set bounds of
    window 1 to {0, 0, winWidth, winHeight}

and this one will move the top window to the centre of the screen

tell application "System Events" to set appList
    to name of application processes whose frontmost is true
set frontApp to item 1 of appList

--calculate the dimensions of the desktop
tell application "Finder"
        set dimensions to bounds of window of desktop
        set screenWidth to item 3 of dimensions
        set screenHeight to item 4 of dimensions
end tell

--calculate the centre
tell application frontApp
        set fSize to bounds of window 1
        set wLeft to item 1 of fSize
        set wTop to item 2 of fSize
        set wRight to item 3 of fSize
        set wBottom to item 4 of fSize

        set windowWidth to wRight - wLeft
        set windowHeight to wBottom - wTop
        set windowTop to (screenHeight - windowHeight) / 2.0

set bounds of window 1 to
    {(screenWidth - windowWidth) / 2.0, windowTop,
    (screenWidth + windowWidth) / 2.0, windowTop + windowHeight}
end tell

move your windows with abandon!

rss feed link