我正在运行一个applescript程序,我要求用户输入他们的名字。如果用户单击"OK",则名称存储到我想要的变量中。但是,如果用户点击"取消",那么程序就会退出。我如何设置这个隐藏"取消"按钮,所以它不是一个选项点击,或设置一个循环,以便如果取消被点击,它只是继续要求用户输入他/她的名字,直到它被输入?
提前感谢。
display dialog "Please Enter Your Name." default answer " " with title "Enter Name"
简单解决方案
display dialog "Please Enter Your Name." default answer " " with title "Enter Name" buttons {"OK"} default button 1
隐藏取消按钮的方法如下:
display dialog "Please Enter Your Name." default answer " " buttons {"ok"} with title "Enter Name"
set a to the text returned of the result
但是如果你想要重复,那么使用这个(我已经做了,所以他们也必须输入一些东西,而不是只按ok键结束:
repeat
display dialog "Please Enter Your Name." default answer "" buttons {"ok", "cancel"} default button 1 with title "Enter Name"
set a to the text returned of the result
if the button returned of a is "ok" then
if the text returned of a ≠ "" then
exit repeat
end if
end if
end repeat
结果如下:
display dialog "Please Enter Your Name." default answer "" buttons {"Submit"} with title "Enter Name" default button 1
if the button returned of the result is "Submit" then
set yourVariable to text returned of the result
end if