Applescript 一个 "Retry" 按钮

Applescript a "Retry" button

我正在编写一个带有密码字段的应用程序:

set password1 to text returned of (display dialog "To continue please enter your special passcode below." buttons {"Cancel", "Continue"} default button 2 default answer "" cancel button 1 with hidden answer)
if the password1 is "passwordhere" then
display dialog "You have entered the password right!

    The right password was: passwordhere
    The entered password was: " & password1 buttons {"Cancel", "Continue"} default button 2 cancel button 1
else
if the password1 is "" then
set password1 to "Empty Passwordfield"
end if
display dialog "You have entered the password wrong!

    The right password was: ********
    The entered password was: " & password1 buttons {"Cancel", "Try Again"} default button 2 cancel button 1
end if
end

现在我的问题是:如何制作一个 "Try Again" 按钮,以便它 return 到第一个显示对话框?这可能吗?如果不是请在回答中说出来。

还有一个问题:这是否也适用于仅2个普通对话?那么在第二个对话框中是一个 "Back" 按钮?如果你按下那个按钮,你会 return 到第一个对话框?

感谢阅读,

乔特

考虑将密码 prompt/dialog 放入 applescript 处理程序中:

on get_password()
-- get password and return true if good, false if bad
end get_password

通过这种方式,您可以根据需要从脚本中的任何其他地方're-call'处理程序。

这是您的代码示例,在您提出问题时重复提示输入密码:

local goodpassword, password1, tryagain, proceed

set goodpassword to false -- initial set
set tryagain to true -- initial set

on getpassword()
    return text returned of (display dialog "To continue please enter your special passcode below." buttons {"Cancel", "Continue"} default button 2 default answer "" cancel button 1 with hidden answer)
end getpassword


repeat while tryagain = true
    set proceed to true
    set password1 to getpassword() -- This calls the prompt for the first time

    if the password1 is "passwordhere" then
        set goodpassword to true
        set tryagain to false
        try
            display dialog "You have entered the password right!
    The right password was: passwordhere
    The entered password was: " & password1 buttons {"Cancel", "Continue"} default button 2 cancel button 1

        on error number -128
            set proceed to false
        end try

    else
        set goodpassword to false
        if the password1 is "" then
            set password1 to "Empty Passwordfield"
        end if
        try
            display dialog "You have entered the password wrong!

    The right password was: ********
    The entered password was: " & password1 buttons {"Cancel", "Try Again"} default button 2 cancel button 1
        on error number -128
            set tryagain to false
        end try
    end if
end repeat