Applescript:使用简单的 repeat/end 重复创建新文件夹以检查名称是否存在
Applescript: make new folder using a simple repeat/end repeat to check if name exists
我正在尝试创建一个脚本来创建一个新的客户端文件夹。那里没有真正的戏剧性,但是当我尝试添加一些检查文件夹是否存在的功能时,我 运行 搁浅了。如果为 false,它将继续创建文件夹,如果为 true,它将重复初始问题(并检查)直到用户输入不存在的客户端名称。我遇到的问题是我可以让它检查 and/or 在检查后创建一个文件夹,但是一旦它创建了一个文件夹我就无法停止循环。
这是我到目前为止所管理的内容
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
我正在尝试创建一个脚本来创建一个新的客户端文件夹。那里没有真正的戏剧性,但是当我尝试添加一些检查文件夹是否存在的功能时,我 运行 搁浅了。如果为 false,它将继续创建文件夹,如果为 true,它将重复初始问题(并检查)直到用户输入不存在的客户端名称。我遇到的问题是我可以让它检查 and/or 在检查后创建一个文件夹,但是一旦它创建了一个文件夹我就无法停止循环。
这是我到目前为止所管理的内容
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