Possible to detect "window exists" for non-scriptable applications?

Hello

I am new to AppleScript. I am trying to detect when a document window in a non-scriptable application is open. When it is open, I want to close the Safari window. The code below basically polls each second to check for the window. However, it seems “Logic Pro” doesn’t understand “if window 1 exists”. I get the error:

“Logic Pro got an error: window 1 doesn’t understand the exists message.”

Is there any way to detect whether a window exists if the application doesn’t understand “application specific” commands? Any advice would be greatly appreciated.

Thanks in advance for you help.
Lars


	tell application "Finder"		
		set window_check to false
		repeat until (window_check)
			if process "Logic Pro" exists then
				if window 1 exists then
					tell application "Safari"
						if window 1 exists then
							close window 1
							set window_check to true
						end if
					end tell
				end if
			else
				tell application "Safari"
					activate
					if first document exists then
						set URL of first document to "http://localhost/"
					else
						make new document with properties {URL:"http://localhost/"}
					end if
				end tell
				set window_check to true
			end if
			delay 1
		end repeat
	end tell

Hi Lars,

even if an application is not scriptable (shame on Apple regarding Logic Pro ;))
System Events knows everything about windows of each single process, but the Finder doesn’t.
So your script should work with

tell application "System Events"
	set window_check to false
	repeat until (window_check)
		if (window 1 of process "Logic Pro" exists) then
			tell application "Safari"
				if window 1 exists then
					close window 1
					set window_check to true
				end if
			end tell
		else
			tell application "Safari"
				activate
				if first document exists then
					set URL of first document to "http://localhost/"
				else
					make new document with properties {URL:"http://localhost/"}
				end if
			end tell
			set window_check to true
		end if
		delay 1
	end repeat
end tell

Hi Stefan

That works perfectly for all 5 of the DAWs which I need to use this for. I can’t thank you enough.

Regards,
Lars

Model: intel mac mini
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)