Stop script dialog?

Hey everybody, working on my very first applescript and I could use a little help. I have searched extensively online, and in these forums, and have yet to find a satisfactory answer to my question.

I have written a very basic script that sounds an emergency alert sound and opens a doppler radar app when I receive an e-mail containing the words “tornado warning.” It is triggered by the rules feature in Mail:

tell application "Finder"
	activate
	open application file "RadarScope.app" of folder "Applications" of startup disk
end tell

set savedSettings to get volume settings

set volume output volume 80

repeat 2 times
	
	tell application "Play Sound"
		
		
		play "Macintosh HD:System:Library:Sounds:EAS1.aif"
		
		
	end tell
	
	delay 19
	
	say "The national weather service in Nashville has issued a tornado warning for Rutherford county in Middle Tennessee. Please seek shelter now." using "Alex"
	
	delay 2
	
	tell application "Play Sound"
		
		play "Macintosh HD:System:Library:Sounds:EAS2.aif"
		
	end tell
	
	delay 9
	
end repeat

set volume output volume (output volume of savedSettings)

What I would like to know, is how to get an alert dialog to stop the script. So that I don’t have to hear it repeat (preferably I would like it to repeat ad infinitum until some button is pressed such as an alert dialog button)

I appreciate all of your help in advance. If you have any questions, I would be glad to answer them.

Hi,

the main problem in your environment is the mail rule.
Rules in Mail.app don’t support user interaction.

A workaround is to use a simple rule script which launches a stand alone AppleScript application (a normal script saved as application bundle). This application can execute the task and is able to display dialog windows

I am still able to get it to display a dialog, I just can’t figure out how to get a button to stop the script from executing. Even if I were to use your method, and have a rule script run this one, I still don’t know how to make the script stop using a dialog.

THanks for the advice!

As AppleScript is single-threaded it’s not possible to keep a dialog window open permanently while executing a script.
This is a workaround


repeat
	set {button returned:buttonReturned} to display dialog "keep script running" buttons {"Stop It!"} default button 1 giving up after 3
	if buttonReturned is "Stop It!" then exit repeat
	say "hello"
	delay 4
end repeat