Stay open app to quit when conditions are met

I know that the whole purpose of a stay-open application may be to stay open forever, but I want my script to be able to terminate itself if certain conditions occur. How to do this?

Thanks,

-Billy

Use a “idle” handler and check for such conditions. Take a look to these or keep asking!
http://macscripter.net/faq/general.php?id=P70
http://macscripter.net/faq/general.php?id=P46

Thanks for the the reply, but not quite the answer I was looking for. Maybe I should clarify: How do I get a stay open script application to terminate itself (not the app that it is “telling”)? In other words, I’m just looking for a simple escape sequence for the stay open application so that I don’t have to manually quit it myself from the dock everytime.

-Billy

Hi,

What jj is saying is to use an idle handler to repeatedly check for a certain condition. If that condition is met, then use the ‘quit’ command to quit to quit the script. Something like this:

global target_date

on run
set target_date to (current date) + 1 * minutes
end run

on idle
set cur_date to (current date)
if cur_date > target_date then quit
set date_string to cur_date as string
say date_string
return 10
end idle

This example checks every 10 seconds if the current date is greater than the target date. If it is greater, then the script quits. Notice that the ‘quit’ command is not in a tell block. Otherwise the target of the tell block qould quit.

If you do not keep a stay open script running, then it will stop. Although it is still open, it is just sitting there not doing anything and can’t quit itself.

gl,