How to tell if dialog box is open

I am fairly new to AppleScript. I have successfully written a small script to automate some actions in a custom program that we are using. The script works by sending keystrokes to the application.

Unrelated to the script, occasionally the program throws up a dialog box asking if we want to download updates and instead of my script talking to the desired part of the program it is entering the keystrokes into the update dialog box.

I’m looking for a way to read the front window or tell if the dialog box is present so I can send keystrokes to close it before the rest of the script executes.

Thanks for any assistance

Without seeing your applescript, here’s a suggestion. I haven’t tested this but it might work.

tell application "whatever"
	activate
	set windowName to name of window 1 --> or document 1
	if windowName is not "whatever name your front window normally has" then
		-- do something because you have found a dialog box
		-- such as keystroke return to get rid of the dialog box
	end if
end tell

Thanks for your post. Unfortunately it did not work.
I get “Could not get name of Window 1 (document 1)”

Are you saying that it couldn’t get the name at all or only when the dialog box was showing?

Because if it only happens when the dialog box is showing you can use that with a try/on error block:

try
	tell application "whatever"
		activate
		set windowName to name of window 1
		-- if there is no error you just continue your script
	end
on error
	-- if there is an error
	-- do something because you have found a dialog box
	-- such as keystroke return to get rid of the dialog box
end

I thought of that. Both conditions returned an error.

Well since it’s a custom application then I can’t really test it, but you basically have to find some value (since the name of the window doesn’t work) that you can get when the window is in front but can’t get when the dialog box is in front, then use the try/on error stuff.

So test for things like the size of the window, or a value in a text box in the window etc. and eventually you’ll find something that errors when the dialog is showing.

Hi:

Trying to GUI script an app the other day, I was able to do something like this:


tell application "System Events"

	if exists window "Connection Details" of process "VNCViewer" then
		
		delay 1
		
		keystroke (ASCII character 3) -- or whatever is appropriate...
		
	end if
	
end tell

Since the dialog is likely to be frontmost, you may not even need to tell the process (specifically, by name) to do the action.

Worth a try.

Peter B.