applescript中是否有条件命令让用户退出应用程序?



applescript中是否有一个条件命令可以让用户退出应用程序。我把我的applescript变成一个使用automator的应用程序。然而,脚本被设置为持续运行,直到它循环遍历数百个脚本。是否有一个条件命令语句,我可以使用它来结束应用程序的运行?

property MyUserName : ""
if MyUserName is "" then
    display dialog "User Name:" default answer "" buttons {"Cancel", "Continue…"} default button 2
    copy the result as list to {button_pressed, text_returned}
    set {returnedText, returnedButton} to the result as list ---> {"some text", "OK"}
    if button_pressed is "Cancel" then
        beep
        return
    end if
    if text_returned is not "" then set MyUserName to text_returned
    say "Hello," using "Karen"
    say (returnedText) using "karen"
else
    display dialog "Stored user name: " & MyUserName buttons {"Ok"} default button 1 with icon 1
end if

say "For your information, please start the Amuse App everytime you log on... and I will speak to you at random times during your visit with me." using "Karen"
delay 20

try
    repeat 105 times
        set pathToMyFolderOnDesktop to ("Macintosh HD:Users:jr:Desktop:") & "Dsource:" as alias
        set rnd to (random number from 1 to 105)
        set rndFileName to (rnd as text) & ".scpt"
        set FullPath to pathToMyFolderOnDesktop & rndFileName as text
        set myScript to load script (FullPath as alias)
        run script myScript
    end repeat

on error the error_message number the error_number
    display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
    return
end try

你可以这样做:

display dialog "Shall I proceed?" buttons {"Quit", "Proceed"} default button 2 giving up after 10
if button returned of result is "Quit" then tell me to quit

它使用giving up after 10,这意味着当用户不按任何按钮时,脚本将在10秒后继续执行。

当它是一个自动应用程序时,从外部退出它不是那么容易,因为它们在系统中看起来都是一样的,所以你不能真正使用应用程序名称来告诉它退出。也许可以使用完整路径,如:

tell application "/Volumes/Applications/MyAutomatorApp.app" to quit

(你可以把你的自动驾驶应用拖到脚本中粘贴到完整路径中)

最新更新