Help with Script, please... Application won't quit!

I have a script that won’t quit when I try to log out from the system. So that log out is canceled.

My script is a bit complex and I wrote another simpler script to give a similar example to mine.



repeat 100 times
	
	beep
	
	delay 5
	
end repeat


I save the above code as an application.

why cant I quit it by clicking on > file > quit ?

I have to kill the application on the terminal…

Thanks for posting!

Hi,

Your script is hogging the cpu. You can quit the script with the keystrokes Command + “.” (period). This causes an error. There is a better way to write your script though instead of hogging the cpu. You might use an idle handler where it gives up the cpu for a certain amount of seconds. Or you could use the ‘sleep’ unix command maybe. But somewhere in the back of mind I’m thinking about something connected to the logout.

later,

Hi Kel!

Thanks for posting!

My “real” script executes a shell script (curl) on an equipment on my local network, a scale that displays a certain weight. Then if the weight on the scale changed, it writes a line with the new weight on a log file.

The script is fully functional today, except for the fact that I have to kill it before logging out.

I would like to have the script running on another computer on the network. But can’t do it now because of the fact that it would prevent people from logging out.

This is why I posted this topic.

I tryed once a “on idle” aproach. But this made my script completely useless.

In fact my script use a “repeat while true” statement.

Could you post me an example of how you would aproach the problem with an idle handler?

Thanks!

Hi folks!

I have done some research on Apples discussions board, and it seems I found a solution to my small problem.

This seems to do the Job, and still, is quitable.



property repeat_time : 5

on idle
	
	repeat while true
		beep
		return repeat_time
	end repeat
	
end idle


Thanks!

Hi Bernardo,

Actually the comparable scri pt wou ld look like this:

property repeat_time : 5

on idle
beep 1
return repeat_time
end idle

Instead of hogging the cpu, it gives up the cpu for 5 seconds. Then it returns and beeps 1 time. The only problem is the 1 second limit on the idle time and you have to save it as stay open application.

Your original script would look like this:

property repeat_time : 5
global the_count
on run
set the_count to 0
end run
on idle
beep 1
set the_count to the_count + 1
if the_count = 100 then quit – don’t put this in a tell block
return repeat_time
end idle

gl,