我正在尝试创建一个脚本,创建一个新的客户端文件夹。没有真正的戏剧性,但当我试图添加一些检查文件夹是否存在的功能时,我搁浅了。如果为false,它将继续创建文件夹,如果为true,它将重复初始问题(并检查),直到用户输入不存在的客户端名称。我遇到的问题是,我可以让它检查和/或创建一个文件夹后,它已经检查,但我不能让循环停止一旦它已经创建了一个文件夹。
这是我到目前为止所做的
tell application "Finder"
activate
repeat
set newClientName to text returned of (display dialog "Enter New Client Name" default answer "")
set thePath to "MATRIX:Designs:Digital:Clients:"
set theFolder to thePath & newClientName
if (theFolder exists) = true then
display dialog "There is already a Client with that name"
else
make new folder at thePath with properties {name:newClientName}
end if
end repeat
end tell
请指教
只要exit repeat
成功循环。
您应该检查folder
而不是文本字符串路径
set thePath to "MATRIX:Designs:Digital:Clients:"
tell application "Finder"
activate
repeat
set newClientName to text returned of (display dialog "Enter New Client Name" default answer "")
if exists folder newClientName of folder thePath then
display dialog "There is already a Client with that name"
else
make new folder at folder thePath with properties {name:newClientName}
exit repeat
end if
end repeat
end tell