温馨提示:本文翻译自stackoverflow.com,查看原文请点击:macos - SHELL/AppleScript: On "Cancel" stop AppleScript and Quit Shell
macos shell applescript

macos - 外壳/ AppleScript:在“取消”上,停止AppleScript并退出Shell

发布于 2020-04-05 00:50:05

我只是想在用户点击“取消”按钮之后停止/退出脚本。

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'

尽管它将继续执行剩余的Shell脚本。我也尝试过do shell script "exit"return并以各种方式重新定义了“取消”按钮。

任何建议将不胜感激

查看更多

提问者
Ryul
被浏览
127
Philippe 2020-01-31 23:08

这应该是必需的:

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