12

I would like to create a tool that allows you to set windows to exact sizes on the pixel scale to be able to have more precise screen divisions.

For example, if I had four Terminal windows (and I didn't have something cool like iTerm to do this for me), I'd like to be able to set each one to 1/2 screen height and 1/2 screen width, and people to position them via x, y coordinates so that they took up the entire screen, and exactly one fourth of them individually.

Can this be done using applescript?

14

Yes, this can be done using AppleScript. Read this link to understand the code and then try and implement it yourself for your specific situation.

Here is another link that describes the bounds of a window in detail.

Example:

tell application "Finder" to set the bounds of the front window to {24, 96, 524, 396}

would set the Finder window to be in the top left corner.

Mac App Store- BetterSnapTool:

Note: I would check out BetterSnapTool. It does exactly what you want for $1.99. I use it myself and I find it invaluable, especially at such a low price.

5
  • Also, is there a preset variable of the screen resolution?
    – JShoe
    Aug 6 '13 at 5:02
  • 1
    No, but you can run system_profiler SPDisplaysDataType | grep Resolution in iTerm to get the screen resolution. Or open up System Profiler and it should tell you. One more thing to try is to use the bounds property of a window in AppleScript: you can make a Finder window open completely (drag to fill entire screen) and then run tell application "Finder" to get the bounds of the front window in AppleScript and it will return the bounds, which represents the area of the window. Aug 6 '13 at 5:08
  • How do I tell it to go to the full bounds of the csreen if I don't know what they are?
    – JShoe
    Aug 6 '13 at 5:26
  • If you expand the Finder window so that you know it is at its maximum width and height of your screen and then execute tell application "Finder" to get the bounds of the front window, this will return the area of the window which is the full bounds of the screen. It will return it in this format: {72, 90, 512, 481}. Aug 6 '13 at 5:29
  • 37:43: execution error: Keine Berechtigung zum Senden von Apple-Events an Finder. (-1743) Jun 17 at 6:08
6

I found a few Apple scripts online, but they all seemed to be outdated and no longer worked. I managed to combine them into the following script, which worked for me:

set theApp to "Terminal"
set appWidth to 1280
set appHeight to 800

tell application "System Events" to tell application process theApp
    tell window 1
        set position to {50, 50}
        set size to {appWidth, appHeight}
    end tell
end tell

There are couple of caveats:

  • If the desired appHeight is greater than the main displays's height, the resizing won't quite work. I ended up setting my external monitor as a main display.
  • You need to add accessibility permissions for the "Script Editor" app as displayed below:

enter image description here

2
  • Which access rights have to be activated exactly? Jun 17 at 6:09
  • 1
    @DarwinOSX I added a screenshot to the my response showing which permission is needed. Jun 17 at 12:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .