Warm tip: This article is reproduced from stackoverflow.com, please click
macos shell applescript

SHELL/AppleScript: On "Cancel" stop AppleScript and Quit Shell

发布于 2020-04-05 00:24:49

I am simply trying to stop/exit the script after the user hits "Cancel" butoon.

osascript -e 'display dialog "" buttons {"Cancel","Continue"} default button 1 Cancel button 1 with icon stop
set xxxx to button returned of the result
if xxxx is "Cancel" then
    error number -128
end if'

Although it continues executing the remaining Shell script. I have also tried do shell script "exit", return and redefining the cancel button in various ways.

Any advice would be much appreciated

Questioner
Ryul
Viewed
182
Philippe 2020-01-31 23:08

This should be what's required :

osascript -e 'display dialog "" buttons {"Cancel","Continue"} default button 1 Cancel button 1 with icon stop
set xxxx to button returned of the result
if xxxx is "Cancel" then
    error number -128
end if' || exit