我有一个对话框,可以打开输入和存储用户输入(名称)。 出错(这是由于没有输入名称或名称已经存在)我希望对话框重新打开。最后,如果第二次尝试再次失败,请打开一个对话框,说明并退出。
问题是,无论名称是否存在,都会始终显示所有3个对话框。 我错过了什么?
try
display dialog "Specify a new folder name:" default answer "John The Dog"
set newName to (text returned of result)
on error errorMessage number errorNumber
end try
try
display dialog "Specify a DIFFERENT folder name:" default answer "John The Dog12"
set newName to (text returned of result)
on error errorMessage number errorNumber
end try
try
display dialog "NAME ALREADY EXISTS! The program will now exit." with icon caution buttons {"EXIT"}
end try
谢谢!
答案 0 :(得分:0)
试试这个。注意我没有测试这个,但它应该工作。只需将此代码替换为您尝试获取文件夹名称的代码。
您基本上可以根据需要创建任意数量的dialogTexts / defaultAnswers组合,它将起作用。祝你好运。
-- get the names of all the folders in the targetFolder
tell application "Finder" to set targetFolderNames to name of folders of folder targetFolder
set dialogTexts to {"Specify a new folder name:", "Specify a DIFFERENT folder name:"}
set defaultAnswers to {"John The Dog", "John The Dog12"}
repeat with i from 1 to count of dialogTexts
display dialog item i of dialogTexts default answer item i of defaultAnswers
set newName to (text returned of result)
if newName is not "" and newName is not in targetFolderNames then exit repeat
if i is (count of dialogTexts) then
display dialog "NAME ALREADY EXISTS! The program will now exit." with icon caution buttons {"EXIT"} default button 1
return input
end if
end repeat
-- do something with newName