First: I can absolutely write this myself, only look at this question for the fun on it.
I started to write this myself and thought “This algorithm is stupid. There is clearly a much better way to write this.”
Usually when I think that, I stop writing it and a better solution pops into my head within the next couple of days.
But just for the fun of it, I thought I’d post this one and see if anyone comes up with something elegant.
I’ve been UI scripting an application with no dictionary and little access to System Events UI scripting, using mostly scripted mouse clicks and keyboard.
If the user places some of the application windows so they overlap, the script breaks - the clicks it thinks are in one window are sent to another window in front of it. If they’re really unlucky in how the windows overlap, it could break catastrophically - clicking buttons to delete things.
But while I can’t get much UI info or click UI elements with System Events in this App, I can at least get the open window’s origin points and sizes… so that’s enough info to determine whether or not there are any overlaps, and warn the user to sort out their windows and run the script again if there are.
tell application "System Events"
tell application process "ICISS Scanner"
set frontmost to true
delay 0.2
set windowPositions to the position of every window
set windowSizes to the size of every window
end tell
end tell
The grid here is top left corner of screen = X0, Y0, counting up as you go right or down.
windowPositions is the coordinates for the top left corner of each window.
windowSizes is the width and height
Test data set results:
windowPositons: {{18, 730}, {25, 980}, {23, 28}, {101, 227}, {374, 450}, {502, 23}}
windowSizes: {{174, 223}, {216, 168}, {159, 255}, {159, 135}, {447, 455}, {1070, 1572}}
Anybody want to take a crack at an elegant way of determining whether or not there are any overlaps?
If not, I’ll probably think of a good way, or else get bored waiting for an idea and just hammer through it in an inelegant way.
Thanks,
Tom.