如何结束AppleScript进程

如何结束AppleScript进程,applescript,Applescript,基本上,我想做的是在脚本启动时在右上角打开一个窗口,您可以单击对话框中的按钮,结束该过程 我不知道该怎么做,因为我是AppleScript新手。 我试过这个: display dialogue "Here is where you can end the process.." buttons {"End Process"} copy the result as list to {text_returned, button_pressed} if button_pressed contains "

基本上,我想做的是在脚本启动时在右上角打开一个窗口,您可以单击对话框中的按钮,结束该过程

我不知道该怎么做,因为我是AppleScript新手。 我试过这个:

display dialogue "Here is where you can end the process.."
buttons {"End Process"}
copy the result as list to {text_returned, button_pressed}
if button_pressed contains "End Process" then
tell application Spammer
end process
end tell

谢谢你的帮助!谢谢

首先,查看AppleScript编辑器的首选项。在那里,您应该激活脚本助手(第二个选项卡)。现在您可以键入一些内容(尝试显示…)并使用Escape键获得代码完成列表

下一步:按CTRL键单击AppleScript,它会显示可插入的脚本列表。试试“对话框”菜单。这通常非常有用

不管怎样,你可能想要这样的东西:

display dialog "Quit Spammer" buttons {"Cancel", "Quit"} default button 2

if the button returned of the result is "Cancel" then

    -- action for 1st button goes here
    return

else

    -- action for 2nd button goes here
    tell application "Spammer" to quit

end if

在不太复杂的情况下,您可以定期提示用户退出:

set counter to 0
set interval to 5

repeat
    delay 1
    set counter to counter + 1
    --insert your code that does things here

    if counter mod interval = 0 then
        if not gave up of (display dialog "Here is where you can end the process.." buttons {"End Process"} default button 1 giving up after 2) then exit repeat
    end if
end repeat

令人惊叹的!你太棒了,太谢谢你了。此时将显示对话框,并结束该过程。非常感谢你!酷,谢谢你的反馈!哦,等等。有一个问题。在我给出输入之前,脚本的其余部分似乎不会启动。我希望它能在脚本中使用,而不是在任何事情发生之前。是的,结合你的新知识和adayzdon的答案|