Compiled Applescript behaving unexpected.

Hello all,

The Applescript I am developing, behaves different when running from within Script-Editor then it does when compiled as application.
When running within Script Editor the script behaves ad intended.

When the script starts, using both the on run and the on open handlers, it checks if some conditions are met.
If not the user is prompted, conditions are not met and the script terminates.
When compiled as application the ‘me quit’ command simply is not executed. The script continues the rest of the code.

What am I doing wrong here?

Simplified:

on run
set all_ok to checkconditions()
if not all_ok = “OK” then
display dialog “Conditions not met, quitting now.” buttons {“Bummer”}
me quit
end if

→ From here rest of the code.

end run

on checkconditions()
– really nice code here.
end checkconditions

Don’t use (me) quit. Use error number -128.

Hello Shane,

Thank you for your reply.
Unfortunately your suggestion does not resolve my question.

First off, since the dialog box does not have a default ‘Cancel’ button, error -128 is not raised.
Next, error -128 by it self will not quit the script, something must follow.

I found however the solution:
In stead of (me) quit, simply use return

So:

===
on run
set all_ok to checkconditions()
if not all_ok = “OK” then
display dialog “Conditions not met, quitting now.” buttons {“Bummer”}
return
end if

I think you’ll find it does.

No – you have to raise an error.

Correct – that’s why I said error number -128. You left out a very important word.

Now change return to error number -128 and see what happens.

The advantage of raising an error over using return is that you can also use it in handlers.

Hello Shane,

Thanks again for your reply.
I understand what you’re saying and indeed it is an advantage to be able to use the error number -128 result in a handler!

Thanks!