It is a simple question. In TextEdit, how does on go on setting the front document with applescript?
This works for me (the first step could be replaced by getting names of windows from W)
tell application "TextEdit" to set D to documents
activate application "TextEdit"
set W to windows of application "TextEdit" -- I have three open, the list is in order
set index of item 2 of W to 1