[Applescript Studio] Stopping an action

Hallo,
in my apps I have a repeat that resize my images in photoshop.
I want set a stop button, so I can exit repeat and stop the action.

I’m trying, but it doesn’t work.

I have this code:


		if the name of theObject is equal to "start" then
		repeat with i from 1 to mycounttot
--my actions
				if the name of theObject is equal to "stopp" then
					exit repeat
				end if

end repeat


I think that the problem is that I have set the stop button inside the button start?

How can I do to set my stop button?
If I set exit repeat outside the repeat obviously it doesn’t work.

Can you help me?
Thanks

Hi,

It says that this is an AppleScript Studio application so I assume that you have a window where you have both the “Start” and “Stop” buttons to be clicked by the user.

If so, I would say that there is no need for you to put the “Stop” code inside the your repeat block. Instead, have a separate “click” handler for each button, one to start the actions you want, with repeat loop, and another, for “stop”, to invoke actions that would kill the on-going process.

Good luck!

archseed :slight_smile:

Model: iBook G3
AppleScript: 1.10.3
Browser: Camino 1.0
Operating System: Mac OS X (10.4)

ok,
but if I put the stop button outside I can’t use exit loop!

What action can I use to stopping the loop if I’m outside?

I don’t want to quit my app but only stop the action.

Thanks for your reply!!!

ok,
I’ve found this code that is ok:

property userCancelled: false

if the name of theObject is equal to “start” then
set my userCancelled to false
repeat with i from 1 to mycounttot
–my actions
if my userCancelled is true then
exit repeat
end if
end repeat
if the name of theObject is equal to “stop” then
set my userCancelled to true
end if

Hi Coo,

Am glad you found a solution.

I was trying something out to see if I could help solve your dilemma but you beat me to it.

Congratulations!

archseed :slight_smile:

Hi Coo,

Just a parting thought…you could perhaps trim your codes by one line by eliminating the “set userCancelled to false” before the repeat loop since the property “userCancelled” is already set to false.

Ciao.

archseed :slight_smile: