How to check if a Finder window is open in the current space/desktop

Hallo,
someone of you out there might be able to help me out.

I did not expect that none of the AI-tools ChatGPT(Turbo3.5) , Copilot(GPT-4) and Gemini could "improve/rewrite" the below script.

None of them produced a working result...(some had even syntax errors etc...)


The problem appears to be "simple":

I want to check if at least one Finder window is open in the current selected space.
The Apple script below kind of "works", but not quite as expected as it finds also open Finder window in other spaces.
Like so:

..

tell application "Finder"
	if exists window 1 then
		# display dialog "at least one Finder-window open"
		tell application "BetterTouchTool" to set_string_variable "is_finder_window_open" to "yes"
	else
		# display dialog "no Finder-window open"
		tell application "BetterTouchTool" to set_string_variable "is_finder_window_open" to "no"		
	end if
end tell

Thx,
Christian

MacOS: 14.5
BTT; 4.581

This appears to work ( at least one Finder window is open in the current selected space)


tell application "System Events"
	if exists (window 1 of process "Finder") then
		# display dialog "Finder window is open."
		tell application "BetterTouchTool" to set_string_variable "is_finder_window_open" to "yes"
	else
		# display dialog "Finder window is not open."
		tell application "BetterTouchTool" to set_string_variable "is_finder_window_open" to "no"
	end if
end tell