Can I use the Delay Function in This Way?

Here’s what I’m wondering. Can you create if/then statements with Delay like this



press button <the button on my program>
if delay = 3 then
<code for continuing on with my script>
end if

If I can’t use delay like this, is there another way? My script is retrieving information from transaction numbers. Only some transaction numbers take forever when pressing the button needed to get the info. And for those specific transaction numbers, I don’t even need that info anyway, so I want to find a way to have my script skip over them.

Hi,

no you can’t use delay in this way.
Probably there is a work around, but I guess we need a bit more specified informations :wink:

I’ll try to be more specific but let me start by stating in general what I’m trying to do :smiley:

I want my script to somehow count the seconds it takes for an action to be performed, and if that action takes more than 3 seconds, then it skips that action.

Ok, to be more specefic:

There’s a button on this transaction software my script is pressing to get the info I need. Almost always, the info is retrieved instantly while going down the list of transaction numbers I’m feeding into the program to lookup. Every once in awhile, a transaction number will come up that takes about a minute to retrieve the info when my script presses the button. What I want my script to do is to somehow count the seconds after pressing the button that retrieves the info, and if it ever counts to 3 seconds, then it’ll know to skip that transaction number and continue on down the list.

Unfortunately, I can’t distinguish which kind of transaction numbers are going to be like this beforehand.

If nothing happens within the three seconds you can use something like this


press_button()
delay 3
if (number is retrieved) then
	do_something()
else
	do_something_else()
end if

or with a timeout repeat loop of 60 seconds


press_button()
repeat with i from 1 to 60
	if (number is retrieved) then
		do_something()
		exit repeat
	else
		if i is 3 then do_something_else()
		exit repeat
	end if
	delay 1
end repeat

This code a quite schematic, but I hope, it makes clear the process

thank you stefanK, that makes perfect sense. i’ll have to try it out. the only problem i think i might have, that i nelgected to mention, is that my script that presses the button on the program I have more lines of code that’s needed to get my info.


press button()
set loopCount to 8
set counter to 0
set loopstop to false
repeat until loopstop is true

set variable to the text of label (label name [1, & loopCount & ]

set loopCount to loopCount +1
set counter to counter +1

end repeat


that’s just a quick breakdown if what I’m doing after the button is pressed in the script. I’m basically trying to count how many lines there are in the results, hence the need for the repeating loopCount variable. For each: label [1,X] it counts, my counter is going up one. Anyway, I’m thinking that might get in the way of your second idea. I’ll try at the first one, but it might slow down my script too much (because sometimes the delay is only 1 sec, and sometimes it’s like 5 or so (when hitting those quick transaction numbers)… iif i were to make it always 5 it would be too slow)