Set size of window to exact pixels, and place via x, y coordinates
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?
Solution 1:
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.
Solution 2:
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: