Applescript 重新打开上一个对话框时出错

Applescript 重新打开上一个对话框时出错,applescript,Applescript,我有一个对话框,可以打开来输入和存储用户输入(名称)。 出现错误时(可能是由于未输入名称或名称已存在),我希望对话框重新打开。最后,如果第二次尝试再次失败,请打开一个对话框,说明该操作失败并退出 问题是,无论名称是否存在,所有3个对话框都将始终显示。 我错过了什么 try display dialog "Specify a new folder name:" default answer "John The Dog" set newName to (text returned o

我有一个对话框,可以打开来输入和存储用户输入(名称)。 出现错误时(可能是由于未输入名称或名称已存在),我希望对话框重新打开。最后,如果第二次尝试再次失败,请打开一个对话框,说明该操作失败并退出

问题是,无论名称是否存在,所有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 

谢谢

试试这个。注意我没有测试这个,但它应该可以工作。只需将此代码替换为您尝试获取文件夹名称的代码

基本上,您可以根据需要创建任意多个DialogText/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

检查名字是否存在的代码在哪里?嗯,我只有这些。如果我指定了一个现有名称并将退出,进程将自动显示一个错误。完整脚本如下:您缺少创建新文件夹的代码。。。