repeat loop double

Hi,
I have a script I run as a modem listener. The script runs very well untill it comes to quitting it!

I have a repeat within a repeat and I cn cancel it when running as an app but can’t quit it!

Any suggestions? ~I need both Repeat loops otherwise the app stops listening!!

set theLibraryPath to alias ":Library:Application Support:PurplePandaCID:addbook2.scpt"
try
on error
	do shell script "killall PurplePandaCIDusrobo3.app >/dev/null 2>&1 &"
end try

on quit
	do shell script "killall PurplePandaCIDusrobo3.app >/dev/null 2>&1 &"
	continue quit
end quit
set portRef to serialport open "/dev/cu.usbmodem0000001"
delay 1
set xstr to "AT+VCID=1" & return

serialport write xstr to portRef
delay 1

repeat
	repeat -- without second repeat it stops reading the output read_numb
		
		
		set read_numb to serialport read portRef
		
		if read_numb contains "NMBR" then
			set xstr to "AT+VCID=0" & return
			
			set theLoadedScript to load script theLibraryPath
			tell theLoadedScript to run
			delay 1
			exit repeat
		else
			exit repeat
			
		end if
	end repeat
end repeat

Model: Power MAc
AppleScript: 2.0.1
Browser: Safari 531.9
Operating System: Mac OS X (10.5)

I can not test this or compile script due to the app and Modem which I do not have. And its hard to guess the behaviour you want.

Part of the problem you are having is due to the exit repeats.
Its always best to give a repeat a condition to work against or with.

I would suggest two possible answers.
1, you make it a Stay open app, and use an on idle handler.

set theLibraryPath to alias ":Library:Application Support:PurplePandaCID:addbook2.scpt"
try
on error
	do shell script "killall PurplePandaCIDusrobo3.app >/dev/null 2>&1 &"
end try

on quit
	do shell script "killall PurplePandaCIDusrobo3.app >/dev/null 2>&1 &"
	continue quit
end quit
set portRef to serialport open "/dev/cu.usbmodem0000001"
delay 1
set xstr to "AT+VCID=1" & return

serialport write xstr to portRef
delay 1
set idleCheck to 1 --seconds
on idle
	
	set read_numb to serialport read portRef
	
	if read_numb contains "NMBR" then
		set xstr to "AT+VCID=0" & return
		
		set theLoadedScript to load script theLibraryPath
		tell theLoadedScript to run
		return idleCheck 
	else
		return idleCheck 
		
	end if
end idle

2, you give you repeat a condition.

set theLibraryPath to alias ":Library:Application Support:PurplePandaCID:addbook2.scpt"
try
on error
   do shell script "killall PurplePandaCIDusrobo3.app >/dev/null 2>&1 &"
end try

on quit
   do shell script "killall PurplePandaCIDusrobo3.app >/dev/null 2>&1 &"
   continue quit
end quit
set portRef to serialport open "/dev/cu.usbmodem0000001"
delay 1
set xstr to "AT+VCID=1" & return

serialport write xstr to portRef
delay 1

set counter to 0
   repeat until counter = 100  
       
       
       set read_numb to serialport read portRef
       
       if read_numb contains "NMBR" then
           set xstr to "AT+VCID=0" & return
           
           set theLoadedScript to load script theLibraryPath
           tell theLoadedScript to run
		   set counter to counter + 1
           delay 1
          
       else
           exit repeat
           
       end if
end repeat

ok cool,
I understand the set counter to the repeat.
The app forced to quit through the “kill” command is the script running as an app so in effect “whatever app”.

Both of your solutions exit out of the repeat loop so not listening to the modem.

In effect I want to open the modem using the string AT+VCID=1

keep listening hence the repeat within the repeat when a call comes in it fires the first script addbook2.scpt which looks up various info.

Then continues the repeat ‘listens’ until another call comes in.

This works but I still have the same problem where I can’t quit the scrpt when it runs as an app or a script.
When in script editor i can press appleKEy . to stop it with a major delay

set theLibraryPath to alias ":Library:Application Support:PurplePandaCID:addbook2.scpt"
set portRef to serialport open "/dev/cu.usbmodem0000001"
delay 1
set xstr to "AT+VCID=1" & return

serialport write xstr to portRef
delay 1

set counter to 0
repeat until counter = 100
	
	
	set read_numb to serialport read portRef
	
	if read_numb contains "NMBR" then
		set xstr to "AT+VCID=0" & return
		
		set theLoadedScript to load script theLibraryPath
		tell theLoadedScript to run
		set counter to counter + 1
		delay 1
		
	end if
	
	
end repeat

The problem is quitting the script either as a script or when it’s running as an app.

Any more suggestions?

P.s if u want both scripts plus instructions pm me, I won’t make them open yet as most won’t get any joy!

Its a little cheesy, but… create a Text Edit document “untitled” and then run this script, your code will loop until you type “stop” in the Text Edit document

repeat until (text of document "untitled" of application "TextEdit") = "stop"
	-- your script
end repeat

display dialog "All Done"