You can use an Adlib function which checks every second if the script has run long enough, so it can terminate immediately or change the state of a boolean variable so the script can run its last loop to the end
08/27/2016 00:05logical691#3
removed
08/27/2016 00:33elmarcia#4
Code:
Do
...
$Seconds = $endtime - Round($diff/1000)
If TimerDiff($time) > ($endtime * 1000) Then ;Why $endtime here ? shouldn't be $Seconds??
...
Until IsArray($Pix) ; This will exit when found color green, is it OK?
08/27/2016 11:16logical691#5
Removed all my comments because the original question is not being answered so i shall figure it out myself.