How to tell if an app has an open window in the current desktop

If I have an app with an open window in the current desktop, it doesn't have to be frontmost, I can access that window in AppleScript with

tell application "<ChosenApp>"
	set doc to front document
	get name of doc
end tell

But if there is no open window of that app in the current desktop, then the above script will return the name of another document in the same app. (It seems to give the first one that was opened in the current session, but I haven't tested that.)

That's the distinction that I'm trying to tease apart. Sometimes that first-opened doc is the on on the current Desktop, so that's the right name to return. But on another Desktop, I only want a name returned if it's the name of a doc that's actually on that Desktop.

Any ideas?

I found this thread:

It looks like it takes advantage of the fact that System Events can only see windows in the current Space and creates a function that counts them.

I'll be trying it.