Test window exists without enabling assistive access?

I’m writing an AppleScript application that opens a text file in TextEdit, then waits for the user to close the file, and then goes on to do other things.

This code seems to work, but (under Mavericks) only if my application has assistive access enabled. I want to distribute it to users who won’t be comfortable enabling assistive access. Is there an alternative method of testing for the existence or non-existence of a window without requiring assistive access?

Here’s a code fragment to show what I’ve been doing so far (autoPosix is the POSIX path of the “autoexec.txt” file that I want to open):


	try
		do shell script "open" & space & quoted form of autoPosix
	on error errMsg
		activate
		display dialog errMsg
	end try
	tell application "TextEdit"
		tell application "System Events"
			tell process "TextEdit"
				repeat until (exists window "autoexec.txt")
					delay 0.2
				end repeat
				repeat until (not (exists window "autoexec.txt"))
					delay 0.2
				end repeat
			end tell
		end tell
	end tell

This routine is called from a list of options and then returns to the list when done.

By the way, this code runs perfectly well from the AppleScript Editor, because the Editor has assistive access enabled. The problem occurs when the code is in its own application bundle.

Thanks for any help with this.