End Repeating Script

Hi,

Newbie at this but I’m having a hard time figuring how to end this script without quitting the app it’s
controlling. It simply saves some webcam images to a local folder.
Quitting the app does end the script but in this case it seems to always delete a few of the
webcam images it saved. When I run the script from Script Editor and hit Stop it always leaves the saved images
intact.

I run the script from my home automation app, Indigo, if that matters.

Any help greatly appreciated!

Thanks,

Carl

tell application "SecuritySpy"
	launch
end tell
delay 6

repeat
	tell application "SecuritySpy"
		capture image camera number 0 as "/Users/TV/Sites/ss/1.jpg" with overwrite
		delay 0.3
		capture image camera number 1 as "/Users/TV/Sites/ss/2.jpg" with overwrite
		delay 0.3
		capture image camera number 2 as "/Users/TV/Sites/ss/3.jpg" with overwrite
		delay 0.3
		capture image camera number 3 as "/Users/TV/Sites/ss/4.jpg" with overwrite
		delay 0.3
	end tell
	delay 1
end repeat

Hi ckeyes888,

When do you want the script to end?

gl

I’d like to end it using another script if possible, or whatever means works best. There’s no time limit,
it just runs as long as I need to view the webcam images.

I tried saving it as an app and running that, but a script to tell that app to quit doesn’t seem to work.

Thanks,

Carl

Hi,

I saved this as a test application:


global exit_repeat

set exit_repeat to false
repeat
	beep 1
	delay 3
	beep 2
	delay 3
	beep 3
	delay 3
	if exit_repeat then exit repeat
end repeat

on quit
	if exit_repeat is true then
		continue quit
	else
		display dialog "Quit?"
		set exit_repeat to true
		return
	end if
end quit

I can’t remember if this is correct usage for the quit handler, but it seems to work. Usually you would use a stay-open application in your case. Using an idle handler would take the place of an infinite repeat loop. Hope it works for you.

gl,

Thanks a bunch. I assume I just incorporate your script into the one I posted? Sorry, real newb at this.

Carl

Hi ckeyes888,

Compare more than incorporate. I don’t have SecuritySpy, so had to use something else.

gl,

Hi ckeyes888,

Maybe I should explain something.

When you quit your application, it interrupts the program. So, say you quit between the 1 and 2 beeps, the quit command is sent to the quit handler. Then, two things can happen either you return to the interrupt or you quit. You said that you wanted to get all four pictures. So, the program will return to the interrupt and continue taking the rest of the pictures if any. Since the boolean value is now true (i.e. the exit_repeat variable), the repeat loop ends and the program quits again to the quit handler and now that exit_repeat is true and it continues on to the application’s quit routine.

Man it was sure hard keeping this short.

gl,

editted: I made a mistake. You always return to the interrupt, but the boolean value changes. Then, you either exit the repeat loop or continue.

Model: MacBook Pro
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Gotcha, thanks for the info. I’ll give it a go.

Carl