Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在AppleScript中,如果按下一个按钮,如何使代码运行,如果按下另一个按钮,如何使其他代码运行?_Applescript - Fatal编程技术网

在AppleScript中,如果按下一个按钮,如何使代码运行,如果按下另一个按钮,如何使其他代码运行?

在AppleScript中,如果按下一个按钮,如何使代码运行,如果按下另一个按钮,如何使其他代码运行?,applescript,Applescript,在Apple脚本中,我正在制作一个假的病毒作为恶作剧,我想知道如何使它在按下一个按钮时运行一些代码,如果按下另一个按钮时运行其他代码。 以下是我目前掌握的情况: display alert "Warning: Non-Standard hardware detected in core files. Please close all applications to allow maximum processing power." delay 5 display alert "Warning:

在Apple脚本中,我正在制作一个假的病毒作为恶作剧,我想知道如何使它在按下一个按钮时运行一些代码,如果按下另一个按钮时运行其他代码。 以下是我目前掌握的情况:

display alert "Warning: Non-Standard hardware detected in 
core files. Please close all applications to allow 
maximum processing power."
delay 5
display alert "Warning: Non-standard hardware detected in 
core files. Core files may become corrupted."
delay 5
display alert "Non-standard hardware reaching dangerous 
level. If you would like to continue with purge process 
and risk your core files, click OK. If you would like to 
abort the process and leave the hardware, exit now." 
buttons {"Ok", "Cancel"} default button 1
我希望这样,如果用户单击“确定”按钮,一件事情发生,如果他们单击“取消”,另一件事情发生。我对苹果脚本没有经验,这是我第一个用它制作的脚本


编辑:我还想知道如何使它在双击时自动运行,因为现在当我双击它时,Apple脚本编辑器打开,我只想让它立即运行。

我重新格式化了您的代码,使其更易于使用。根据需要编辑后,只需在脚本编辑器中将其另存为应用程序。然后双击该新应用程序将启动脚本…而不是脚本编辑器

property displayAlert1 : "Warning: Non-Standard hardware detected in 
core files. Please close all applications to allow 
maximum processing power."

property displayAlert2 : "Warning: Non-standard hardware detected in 
core files. Core files may become corrupted."

property displayAlert3 : "Non-standard hardware reaching dangerous 
level. If you would like to continue with purge process 
and risk your core files, click OK. If you would like to 
abort the process and leave the hardware, exit now."

display alert displayAlert1
delay 5
display alert displayAlert2
delay 5
set buttonReturned to button returned of ¬
    (display alert displayAlert3 buttons {"Ok", "Cancel"} default button 1)

if buttonReturned is "Ok" then
    display dialog "Your Computer Will Explode In 1 Minute" buttons {"Cancel", "OK"} ¬
        default button "OK"
else if buttonReturned is "Cancel" then
    display dialog "Your Computer Will Explode In 2 Minutes" buttons {"Cancel", "OK"} ¬
        default button "OK"
end if

非常感谢。这已经回答了我的问题。@BobRoss既然你说它已经回答了你的问题,那么我可以推动你选择这个答案吗?)这样人们就知道问题已经解决了;b) 其他有类似问题的用户更可能被引导到这里;c) 向你提供帮助的人会得到你(明显)的感谢。当然,这是你的决定,所以我只在你不知道选择是可能的,或者它在社区中带来的好处的情况下提供这个建议。@CJK谢谢你提醒我这个功能,我不知道它存在。我选择了它。