The "tell me to quit" statement is very useful when you run an applescript as an applet or from the script menu, however when developing or debugging scripts in Script Editor it is very annoying since it quits Script Editor rather than just stopping the execution of the script.
Two questions:
-
Is it possible from within a script to check what environment it runs in, something like
if environment is applet then tell me to quit
else display notification "Done" -
How do I exit just the script when it is run in Script Editor? That is, the same result as when you click the stop button in the toolbar.
Best Answer
Current Application
You can get the name of the current application. If the name is
Script Editor
, then your AppleScript is being run within the editor:Detecting the Environment
Alternatively, your AppleScript can access environment variables through the system attribute command. You should be able to determine your process through this information. To see the
HOME
path environment, use:Stopping an AppleScript
To stop the script use the return command. In the AppleScript snippet below, the dialog is never displayed:
return exits the current routine within AppleScript; much like return in other languages such as
c
. Called within the context of the main AppleScript routine, there is nothing to return to, so the script finishes.Compare this to
tell me to quit
, where the snippet causes a quit AppleEvent to be issued to the current process.