on idle loop on AS?

Hi,

Sorry, I was distracted by the error code issue instead of focusing on your question whether your program would work using a repeat loop.

There was an earlier thread on breaking out of a repeat loop in this forum; you can “google” it easily and should be able to peruse the exchanges there.

Briefly, here is the result from that thread: there is no way you can break a repeat loop once your program enters the loop. I have personally tested this myself. Any activating button to get out of the loop will not work. Applescript does not have a “break” command that one can use to get out of the loop as other programming languages have.

archseed :slight_smile:

Hi,

if ChosenButton is {"Start"} then

and

if ChosenButton is in {"Start"} then

are two different things. The second example checks, if the value is in a list of values.
To compare just the name a list doesn’t work. Omit the braces

if ChosenButton is "Start" then

Your script will never exit the repeat loop after pressing the start button, the exit repeat statement must be within the repeat loop

Hi,

I’ve tried StefanK’s suggestion to imbed the exit code inside the repeat loop. Based on my test, this does not work either. Once the loop starts rolling, it seems that no button could stop it until the loop normally terminates itself. Any button to terminate the loop is simply ignored.

I maybe wrong but go ahead and try it yourself.

Good luck!

archseed:)

You are right, AppleScript (Studio) is not able to process multiple tasks,
for example to interrupt a repeat loop with the on clicked handler
The task works only with a flag and the idle handler


property flag : false

on clicked theObject
	set ChosenButton to the name of theObject
	if ChosenButton is "Start" then
		set flag to true
	else if ChosenButton is "Stop" then
		set flag to false
	end if
end clicked

on idle
	if flag then
		tell window of theObject
			tell application "System Events"
				tell application "TextEdit" to activate
				keystroke "a"
			end tell
		end tell
	end if
	return 10
end idle

Hi,

Thanks for the confirmation StefanK.

I just needed a little confidence booster there and also hope that it clarifies things a bit for Keytachi.

Cheers.

archseed :slight_smile:

StefanK this is perfect! thank you so much.
earlier today i thought i could do something like this, but it just wouldn’t stop. now i see where i had it wrong.

by making the on clicked to set the property flag only (instead of having click → type “a” AND set the value to true/false the click would have priority and ignore the value change (i think)). This way, i control the on idle (that acts alone), through the buttons :smiley: (i hope i’m thinking this right).
Also, could i set any variable to start/stop the on idle handler? or does it require the property identifier? (its an identifier right?).

Well, thanks alot to all of you :smiley: every day i learn a bit more :stuck_out_tongue:

You need a property or global variable. Only these can be seen in multiple scopes (every handler has its own scope)