Simple problem I hope!

Hi all,

I’ve been going through amending a couple of old automation scripts I’ve made to remove the generic ‘delay’ periods with a wait for window command.

I’ve written a little script that waits for the window to appear but won’t continue afterwards or is stuck in a loop. In the example below, the window is found but it constantly says ‘test’. When I move the say command after the ‘end repeat’ it doesn’t say ‘test’ at all.

Any help appreciated as I know it’s something I’m just overlooking.

Thanks

Will

tell application "System Events"
	set windowCheck to false
	repeat until (windowCheck)
		if (window 1 of process "softwareApplication" exists) then
			delay 2
		end if
		say "test"
	end repeat
end tell

Hi,

your loop is infinite because windowCheck in never set to true, which is the exit condition of the loop


tell application "System Events"
	set windowCheck to false
	repeat until (windowCheck)
		if (window 1 of process "softwareApplication" exists) then
			set windowCheck to true
			delay 2
		end if
		say "test"
	end repeat
end tell


Edit: easier


tell application "System Events"
	repeat until exists (window 1 of process "softwareApplication")
		delay 0.5
	end repeat
end tell


That’s perfect thanks :smiley:

I knew it would just be something I was overlooking!