How to tell an Applescript to stop executing

jefflovejapan picture jefflovejapan · Dec 23, 2011 · Viewed 42.5k times · Source

Applescript's "choose from list" user interaction has a "cancel" button — I want this "cancel" to tell the script to immediately stop executing. In other words:

 set wmColor to choose from list {"Black", "Black for all", "White", 
     "White for all"} with prompt "What color should the watermark be?" 
     default items "White for all" without multiple selections allowed and 
     empty selection allowed
 if wmColor is false
     *tell script to stop executing*
 end if

Can't seem to find how to do this — does anyone know how?

Answer

user866649 picture user866649 · Dec 23, 2011

Error number -128 is "User Cancelled", and will stop the script - for example:

if wmColor is false then
    error number -128
end if