terminate script when logging/switching off

Hi all,
still new to applescript, so this may sound stupid - sorry for that:

My script runs in the background and checks for a certain file once in a minute. I want it to run all the time, starting when a user is logging in and ending at logout time or when the machine is switched off.
Now, it’s not a problem to make it run, but to make ist stop. I can not switch off. Instead, I get a message saying that the machine could not switch off because of the script still running :stuck_out_tongue:

So, is it possible to make the script terminate at that event (log / switch off)?

Any ideas?
Thanks in advance!

Wow, that is very odd. The script should terminate at logout. I have written a ton oif apps and they terminate at logout without any problem. Are you using something OTHER than an idle handler to control this monitoring app? For example instead of using on idle routine that calls for a return every 60 seconds are you instead just delaying 60 seconds in the middle some other routine that is not a Stay Open app?

Rick

hi, thanks for your reply -

meanwhile the script has undergone some modifications: now it’s no longer running in an eternal loop, instead it’s started by a cronjob. but the problem is still there: when switching off and script execution happen at the same time, I get the aforesaid error message.

So, the question has changed slightly: How can I prevent script execution when the machine is trying to switch off?

stefan