I do keep trying Script Debugger, but always fall back to Script Editor. It would probably be different if I did more AppleScripting, if I spent more time using Debugger, or if I wasn't too cheap to actually pay for it!
Yes, sorry. Stream-of-consciousness happening and I didn't refer back. This might be slightly faster than the previous as it only calls notoriously slow "System Events" if one or more windows are open:
tell application "Finder"
if front window exists then
tell application "System Events"
tell process "Finder"
if enabled of menu item "Close Window" of menu "File" of menu bar 1 then
display dialog "Window is active"
else
display dialog "Desktop is active, window(s) open"
end if
end tell
end tell
else
display dialog "Desktop only"
end if
end tell
I've a feeling that KM is "right" in that the Desktop does exist and is a window (in the broadest sense), while AppleScript is "wrong" in that it doesn't consider "desktop window" to be a window (or even have getable properties) even while stating that it inherits from "Finder window" and, as a result from "window".
But I'm no system API programmer, so pure conjecture on my part...