Re: How do you get a stay-open applet to quit?
Re: How do you get a stay-open applet to quit?
- Subject: Re: How do you get a stay-open applet to quit?
- From: "Nigel Garvey" <email@hidden>
- Date: Mon, 2 Jan 2006 12:05:15 +0000
Michelle Steiner wrote on Sun, 1 Jan 2006 17:38:16 -0700:
>This didn't work for me:
>
>repeat
> (display dialog "Enter the heart rate or percentage" default answer
>eightyPercent buttons {"Cancel", "Percentage", "Heart rate"} default
>button 3)
> set {TR, BR} to {text returned of the result, button returned of the
>result}
> set NR to TR as number
>
> if ((NR is greater than MaxSafe) and (BR is "heart rate")) or ((NR
>is greater than 100) and (BR is "percentage")) then
> set icn to warning
> else
> set icn to informational
> end if
> if BR is "Heart rate" then
> set percentage to ((NR / MaxSafe) * 100) as integer
> display alert "Your heart rate was " & (percentage as text) & "% of
>the Maximum safe heart rate." as icn
> else if BR is "Percentage" then
> set heart_rate to (MaxSafe * NR) / 100 as integer
> display alert "Your heart rate was " & (heart_rate as text) & "
>beats per minute." as icn
> else
> tell me to quit
> end if
>end repeat
Hi, Michelle.
As Adam and David have pointed out, 'quit' only quits a script applet
when it's finished running the script, and the error generated by the
"Cancel" button stops the command from being reached anyway. You need to
trap the "Cancel" error, issue the 'quit' command, and then immediately
repeat the error to stop the script -- at which point the 'quit' command
is obeyed:
repeat
try
set {text returned:TR, button returned:BR} to (display dialog
"Enter the heart rate or percentage" default answer eightyPercent
buttons {"Cancel", "Percentage", "Heart rate"} default button 3)
on error number -128
-- "Cancel" button clicked.
quit
error number -128
end try
set NR to TR as number
if ((NR is greater than MaxSafe) and (BR is "heart rate")) or ((NR
is greater than 100) and (BR is "percentage")) then
set icn to warning
else
set icn to informational
end if
if BR is "Heart rate" then
set percentage to ((NR / MaxSafe) * 100) as integer
display alert "Your heart rate was " & (percentage as text) & "%
of the Maximum safe heart rate." as icn
else -- if BR is "Percentage" then
set heart_rate to (MaxSafe * NR) / 100 as integer
display alert "Your heart rate was " & (heart_rate as text) & "
beats per minute." as icn
end if
end repeat
NG
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden