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

In AppleScript, how to make code run if a button is pressed and other code run if a different button is pressed?

在 Apple Script 中,我正在制作一个假病毒作为恶作剧,我想知道如何制作它,如果按下一个按钮,一些代码是 运行,如果按下另一个按钮, 其他代码 运行s。 这是我目前所拥有的:

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

我想要这样,如果用户单击 "Ok" 按钮,就会发生一件事,如果他们单击 "Cancel",就会发生另一件事。我对 Apple Script 没有经验,这是我用它制作的第一个脚本。

编辑:我还想知道如何在您双击它时使其自动 运行,因为现在当我双击它时,Apple Script Editor 会打开,我只想让它立即 运行.

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

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