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
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.