用户如何选择桌面上要使用 applescript 使用数字名称创建的文件夹数量?
How the user to pick the amount of folders on a desktop to be created with numeric names using 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
我试图让用户选择他们想在桌面上创建多少个文件夹。所需的文件格式为 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