I coerced as string because I always does my best to not use the Finder which I hate.
And, given recent messages I assumed that System Events would not accept to work with aliases when running under Catalina.
For what we are doing, System Events is faster than Finder. If you really need to work with the Finder, you may pick instructions in the code below.
tell application "Finder"
if exists Finder window 1 then
set CurrentDir to target of Finder window 1 as alias
else
set CurrentDir to desktop as alias
end if
end tell
set CurrentPath to POSIX path of CurrentDir --> "/Users/**********/Desktop/"
set NewName to "SAMP"
tell application "Finder" to set ProjectsName to name of CurrentDir --> Desktop
tell application "Finder" to set ProjectsName to CurrentDir --> alias "SSD 1000:Users:**********:Desktop:"
log (current date) (*date dimanche 21 juin 2020 à 11:09:12*)
tell application "System Events"
set maybe to name of every folder of CurrentDir whose name starts with NewName
set fullName to NewName & text -2 thru -1 of ((101 + (count maybe)) as string)
make new folder at end of CurrentDir with properties {name:fullName} --> folder "SSD 1000:Users:**********:Desktop:SAMP01:"
end tell
log (current date) --> date dimanche 21 juin 2020 à 11:09:12-- required less than 1 second
tell application "Finder"
set maybe to name of every folder of folder (CurrentDir as string) whose name starts with NewName
set fullName to NewName & text -2 thru -1 of ((101 + (count maybe)) as string)
make new folder at CurrentDir with properties {name:fullName} --> folder "SAMP02" of folder "Desktop" of folder "**********" of folder "Users" of startup disk
end tell
log (current date) --> date "dimanche 21 juin 2020 à 11:09:26" -- yes, required 14 seconds
set CurrentDir to CurrentDir as string
tell application "Finder" to set ProjectsName to name of folder CurrentDir --> Desktop
tell application "Finder" to set ProjectsName to CurrentDir --> "SSD 1000:Users:**********:Desktop:"
set CurrentPath to POSIX path of CurrentDir --> "/Users/**********/Desktop/"
log (current date) (*date dimanche 21 juin 2020 à 11:09:26*)
tell application "System Events"
set maybe to name of every folder of folder CurrentDir whose name starts with NewName
set fullName to NewName & text -2 thru -1 of ((101 + (count maybe)) as string)
make new folder at end of folder CurrentDir with properties {name:fullName} --> folder "SSD 1000:Users:**********:Desktop:SAMP03:"
end tell
log (current date) (*date dimanche 21 juin 2020 à 11:09:26*)
tell application "Finder"
set maybe to name of every folder of folder CurrentDir whose name starts with NewName
set fullName to NewName & text -2 thru -1 of ((101 + (count maybe)) as string)
make new folder at (folder CurrentDir) with properties {name:fullName} --> folder "SAMP04" of folder "Desktop" of folder "**********" of folder "Users" of startup disk
end tell
log (current date) --> date dimanche 21 juin 2020 à 11:09:41 -- yes, required 15 seconds
And of course I disabled the instruction building a POSIX Path because it wasn’t used.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 21 juin 2020 11:20:29