Search code examples
applescriptbounds

Applescript: pulling apart a bounds record


I have recently ungraded to El Capitan, and the Finder's idea of what the size and position of a new window should be is driving me nuts.

So, I want to write an applescript which will conserve the window's left coordinate, set the top to as high as possible, and set the width and height to certain values.

I can get the bounds:

tell application "Finder"
  set theBounds to bounds of front window
end tell

But if I ask for left of theBounds I get an error.

Surely Applescript provides a way to unpack a bounds?


Solution

  • The bounds property returns type rectangle. This is just a list of four integer values that stands for x/y coordinates of the upper left point and x/y coordinates of the bottom right point. Maybe this little script makes it clearer:

    tell application "Finder"
        set {x1, y1, x2, y2} to bounds of front window
        set {winWidth, winHeight} to {x2 - x1, y2 - y1}
    end tell
    

    You can set coordinates the same way. Define the upper left point's x and y and add your target width to x1 and the target height to y1 to get the third and fourth value.

    Have a nice day, Michael / Hamburg