用户如何使用 applescript 选择要使用数字名称创建的桌面上的文件夹数量?



我试图允许用户选择要在桌面上创建的文件夹数量。 所需的文件格式为 00,01,02,03..10,11,12,13,14...99。 我觉得我快要创建文件夹了,但我被卡住了。 任何帮助将不胜感激!

set targetFolder to desktop
repeat
set subCount to text returned of (display dialog "How many Folders?" default answer 1)
try
if subCount ≠ "" then
subCount as integer
exit repeat
end if
end try
end repeat
repeat with i from 1 to subCount
tell application "Finder" to make new folder at targetFolder with properties {name:i}
end repeat

你很接近。一般来说,最好使用 System Events.app 而不是 Finder(Finder 对文件路径规范更挑剔,并且有时会挂起(,如果您想要零填充文件夹名称,则必须将索引整数转换为字符串。

repeat
set subCount to text returned of (display dialog "How many Folders?" default answer 1)
try
set subCount to subCount as integer
exit repeat
on error
display alert "The value must be an integer"
end try
end repeat
tell application "System Events"
repeat with idx from 1 to subCount
make new folder at desktop folder with properties {name:my zeroPad(idx - 1)}
end repeat
end tell
on zeroPad(a_num)
return text -2 through -1 of ("0000" & a_num as string)
end zeroPad

最新更新