【问题标题】:SHELL/AppleScript: On "Cancel" stop AppleScript and Quit ShellSHELL/AppleScript:在“取消”时停止 AppleScript 并退出 Shell
【发布时间】:2020-01-31 14:09:00
【问题描述】:

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

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 并以各种方式重新定义取消按钮。

任何建议将不胜感激

【问题讨论】:

  • 还有什么shell脚本?请注意,每个 osascript 都在其自己的环境中运行,因此对话框只会取消该脚本 - 您将需要处理来自特定脚本的 result。

标签: macos shell applescript


【解决方案1】:

这应该是需要的:

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

【讨论】:

  • 就是这样!我感到很惭愧,我不知道我可以将&& || 与osascript 结合起来!非常感谢!
猜你喜欢
  • 2013-04-18
  • 2011-08-03
  • 1970-01-01
  • 2012-07-02
  • 1970-01-01
  • 2010-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多