The Bounds Property
If you find yourself always resizing windows, you will probably write many scripts using the bounds property.
The value of the bounds property describes both the size and the position of the target window. This is accomplished by specifying two points: the top-left point of the window and the bottom-right point of the window. These two coordinates, combined into a four-item list, are used to outline the rectangular shape of the window.
Like the position property, the value of the bounds property can be read and edited. First, let’s get the bounds of the frontmost window using this script:
tell application "Finder" to get the bounds of the front window
--> returns something like: {72, 90, 512, 481}
The value of the bounds property is returned as a four-item list of integers representing the area of the window like this: {72, 90, 512, 481}
- List item 1: {72, 90, 512, 481}
The distance in pixels from the left side of the screen to the left side of the Finder window. - List item 2: {72, 90, 512, 481}
The distance in pixels from the top of the screen to the top of the Finder window. - List item 3: {72, 90, 512, 481}
The distance in pixels from the left side of the screen to the right side of the Finder window. - List item 4: {72, 90, 512, 481}
The distance in pixels from the top of the screen to the bottom of the Finder window.
By changing the value of the bounds property, you can resize and reposition a Finder window anywhere on the Desktop. For example, the following script places the front Finder window near the top left of the Desktop and resizes it to 500 pixels in width and 300 pixels in height. Again, the verb set is used to change the value of the property.
tell application "Finder" to set the bounds of the front Finder window to {24, 96, 524, 396}
The Finder window is now repositioned to the top left of the Desktop and resized.
TIP: to set the size of a window to a specific size, such as 500 pixels wide by 300 pixels tall, add the value of the first bounds list item to the desired width to create the third bounds list item: {24, 96, (24 + 500), 396}. Do the same for the window height, and add the value of the second list item to the desired window height to create the fourth list item: {24, 96, 524, (96 + 300)}.
By the way, if you want to know the size of the current computer display, access the value of the bounds property for the Desktop window as shown in the following script. It returns the bounds of the entire Desktop, even if you have more than one monitor:
tell application "Finder" to get the bounds of the window of the desktop
--> returns: {0, 0, 1920, 1200}
The third item of the resulting bounds list is the desktop width, and the fourth item of the bounds list is the desktop height.