Here I have no scope problems so it wil work.
But in other situations I might have to do-some-stuff before aborting and then “abort script” would be nice!
But guess what: just before you answered me I found this:
The statement:
error number -128
will let me abort at any time!
Now why didn’t Apple just put an “abort script” in the language.??
Oh, well. This works. But this is not documented anywhere… :evil:
I have had AppleScriptLanguageGuide.pdf a while and I reference it all the time.
I have found how to trap error codes and how to respond to them.
But nowhere is it mentioned that you can use “error number -128” as a statement do actively do something!
Just one of those things you pick up while learning!
beep
return
display dialog "I will not reach this!"
This “return” will make the script jump to its “caller”. In the example above, we have a implicit “run” handler. Since there is no caller, the script will simply stop execution. If you place, though, the “return” in this example:
doSomething()
display dialog "I should reach this!"
to doSomething()
beep
return
display dialog "I will not reach this!"
end doSomething
Here, the “return” will stop the execution of the “doSomething” handler, then the implicit “run” handler will continue its tasks.
And, as you guess, this is the typical way to handle errors -128 (if you need it):
try
display dialog "foo" --> its the same for choose-whatever
on error msg number n
if n is -128 then --> user cancelled
display dialog "do not cancel, please" buttons {"OK"} default button 1
return run
end if
end try
display dialog "Thanks for hitting "OK"…"