Window Sizing Exercise

I have an application (Beyond Compare) that I’ve used for years. Very responsive developer and the support folks are terrific. A few day ago, the application went from V4 to V5. I don’t usually upgrade my software right away, but with the history of this application, I took the plunge.

Everything functions perfectly in V5, except for one small issue. The software no longer remembers its window position. Minor issue and I’m sure they will soon have a fix. But, in the meantime, I thought it would be an interesting challenge to see if I could come up with a solution. This post is about that solution, hopefully it may help others.

To be perfectly honest, I’m no longer sure where the solution came from. I started here on MacScripter, but spent hours upon hours Googling, going from site to site, so the solution could have come from anywhere.

Background: Beyond Compare creates “workspaces” which are predefined sets of folder comparisons (I mostly use Beyond Compare to make sure that any rsync folder backup scripts that I’ve created are functioning correctly). To activate a “workspace” and put it on the desktop you use a bin/bash shell script as such: /usr/local/bin/bcompare “Rsync Local Backups”, which in my case lists all my folder backup sources as well as all my folder backup destinations. The bin/bash shell script runs via Apple’s Automator.

So, with Automator, you can add AppleScripts, and my thought was to add a script that would size/position the window. Easy, or so I thought.

The first step needed to be (once I positioned the window to the size and location I wanted) to somehow determine its size and location, so I could then plug those numbers into the final script that would do the sizing and actually move the window.

That script ended up being this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events"
	set appOfInterest to "Beyond Compare" --set to desired application
	set windowXY to size of the first window of application process appOfInterest
	display notification (item 1 of windowXY as text) & " x " & (item 2 of windowXY as text) with title "Frontmost window of " & appOfInterest & ":"
end tell

Next, I needed to construct a script to add to Automator that would size and position the window. That script ended up being this:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Beyond Compare" to activate

tell application "System Events" to tell process "Beyond Compare"
	set position of window 1 to {1, 25}
	set size of window 1 to {1152, 810}
end tell

Possibly, there’s an easier way to do what I wanted to accomplish, but it was a fun exercise and I learned along the way. I just thought I’d post it here as appreciation for all the help I’ve been given since joining MacScripter.

1 Like