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

Directory 用户如何使用applescript在桌面上选择要使用数字名称创建的文件夹数量?,directory,applescript,Directory,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

我正在尝试允许用户选择要在桌面上创建多少文件夹。所需的文件格式为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

完美的泰德!再次感谢您!