I have been following this thread, but not in detail, so I may have missed something. It's been nagging me, so I tried an experiment with TextEdit. Could I change the order of windows, specifically, could I move the front window to the back? Here's the script ...
tell application "TextEdit"
activate
set winList to (id of every window) as list
set newOrder to (rest of winList) & {item 1 of winList}
repeat with i from 1 to (count items of newOrder)
set winID to (item i of newOrder)
set index of window id winID to i
end repeat
end tell
The first thing I noticed was that it didn't work. The second thing I noticed was that the script does not change the currently active document window. When you manually change the order of windows, you click on a document window which brings it frontmost AND makes it the active window. (If you add this step manually, the script above does work.)
In order to make the script above work correctly, the last line needs to be added that makes the frontmost window active. Alas, I could find no such command in TextEdit's dictionary. So, I tried things that shouldn't work, but sometimes do.
tell application "TextEdit"
activate
set winList to (id of every window) as list
set newOrder to (rest of winList) & {item 1 of winList}
repeat with i from 1 to (count items of newOrder)
set winID to (item i of newOrder)
set index of window id winID to i
end repeat
set visible of window id (item 1 of newOrder) to false
set visible of window id (item 1 of newOrder) to true
end tell
Now it works! (But, will it help the current problem?)