我正在尝试创建一个程序,要求此人选择一个文件并尝试确认它。当我尝试在if块中添加重复时,我遇到了一个问题。有没有解决方法,因为这令人非常沮丧。提前致谢! :)
display dialog "Select the program"
tell application "Finder"
set filePath to POSIX path of (choose file)
end tell
display dialog "Are you sure this is the program that you have selected?"
buttons {"Yes", "No"}
if the button returned is "No" then
end repeat
else
答案 0 :(得分:-1)
尽管这可能会导致我的死亡,但我会回答。研究这个:
set correctChoice to false
repeat until correctChoice is true -- "is true" is actually unnecessary
--I took this next line out because it's unnecessary - you can put this text in the prompt of the choose file, below
-- display dialog "Select the program"
-- this doesn't need to be (and shouldn't be) in a Finder tell block, so I took that out, too:
set filePath to POSIX path of (choose file with prompt "Select the program")
set myQuery to display dialog "Are you sure this is the program that you have selected?" buttons {"Yes", "No"}
if the button returned of myQuery is "No" then
--there is no repeat loop! Where do you want it? I assume you want the repeat outside of this process
--end repeat
else
set correctChoice to true
end if
end repeat
--maybe do other stuff
做我认为你正在尝试的事情意味着把整个事情放在一个重复循环中,当一个布尔变量设置为true时停止。 if / then要么保留boolean的原始false值,要么将其设置为true,从而允许我们离开repeat循环。 A"解决方法"是限制语言或语言中的错误所需要的术语。您并不需要解决方法 - 您需要正确使用代码。开始简单(!!)并在尝试强制代码执行您认为应该执行的操作之前了解各种块的工作方式。