Re: newbie: how to get result of "cancel"
Re: newbie: how to get result of "cancel"
- Subject: Re: newbie: how to get result of "cancel"
- From: Paul Berkowitz <email@hidden>
- Date: Tue, 23 Jan 2001 21:34:02 -0800
On 1/23/01 8:24 PM, "Cal" <email@hidden> wrote:
>
Bret Linford <email@hidden> wrote:
>
>
> I know that if I do a "choose folder" and the user hits "cancel" that the
>
> script will be killed. How do I get the "result" of a "cancel"? If the user
>
> hits "cancel", I would like to have a dialog box that says something like
>
> "Installation aborted". Thanks!
>
>
Michelle Steiner <email@hidden> replied:
>
>
> try
>
> set x to choose folder
>
> --do something with x
>
> on error
>
> display dialog "Installation aborted"
>
> end try
>
>
>
> There may be other errors than the user cancelling, so you might want to
>
> trap for other errors.
>
>
Yes. As an explanation, when a user hits the "Cancel" button (or
>
types Command-period during script execution), the currently
>
executing command produces the user cancelled error, numbered -128.
>
As Michelle pointed out, there may be other errors. You can make the
>
error handler specific to the cancelling situation:
>
>
try
>
set x to choose folder
>
--do something with x
>
on error number -128
>
display dialog "Installation aborted"
>
end try
>
>
This way, if it's an error other than cancelling, then the script
>
will fail as it should.
>
>
Cal
The trouble is, if the error is in fact the user aborting, this script won't
actually abort after the "Installation aborted" message. It needs to be told
to do so after displaying the message or it will continue on to the rest of
the script.
I sent the following message as the first response to Bret, at 1:55 PM,
before Michelle's. I thought I had taken account of these various things,
but (boohoo) my contribution seems to have slipped past everyone, Bret
included.
Here it is again. Did I also omit something? Maybe your way of ONLY trapping
for the user cancellation might be better in letting the unadulterated
original error message display, but I don't think anything different would
occur this way, would it?
>
Put it inside a try/error block, and in the "on error", you can even
>
specify
>
>
on error errMsg number errNum
>
if errNum = -128
>
display dialog "Installation aborted"
>
else
>
display dialog errMsg & return & return & errNum
>
end if
>
error number -128 -- terminates for real afterwards
>
end try
>
>
I never gave Bret the explanation, as you did, Cal: a bad oversight on my
part. I'm glad you did so.
--
Paul Berkowitz