You may try with :
tell application "Finder"
if ProjectsFolder = "Projects" then
--Prompt to Choose a Client Name
set ProjectNamePrompt to text returned of (display dialog "Please enter your project's business name:" default answer "" buttons {"Cancel", "Create"} default button "Create")
set BaseName to cleanText(ProjectNamePrompt)
if BaseName contains "the" then
display dialog "The folder name will contain the letters " & quote & "the" & quote buttons {"Cancel", "Continue"} default button 2 with icon caution
end if
set i to 1
repeat 99 times
set NewName to BaseName & (text -2 thru -1 of ("0" & i))
try
alias ((CurrentDir as text) & NewName)
set i to i + 1
on error
tell application "Finder" to make new folder at CurrentDir with properties {name:NewName}
exit repeat
end try
end repeat
else
display dialog "Open your Clients 'Projects' folder first" buttons {"OK"} default button "OK" with icon caution --or use icon stop
end if
end tell
on cleanText(theText)
set lowerCase to "abcdefghijklmnopqrstuvwxyz"
set upperCase to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set theNumbers to "1234567890"
set cleanedText to {}
set characterCount to 0
repeat with aCharacter in theText
set aCharacter to contents of aCharacter
if aCharacter is in theNumbers then
set end of cleanedText to aCharacter
set characterCount to characterCount + 1
else if aCharacter is in lowerCase then
set end of cleanedText to (item (offset of aCharacter in lowerCase) of upperCase)
set characterCount to characterCount + 1
end if
if characterCount = 4 then return (cleanedText as text)
end repeat
display dialog "The project name does not contain four usable characters." buttons {"OK"} cancel button 1 default button 1 with icon stop
end cleanText
But the script will not convert accented lowercase chars if there are some in the entered string.
More, there is no reason to behave this way if there is the word “the” in the entered string.
Taking care of this case is really simple. It’s done in my proposal.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 21 juin 2020 22:21:32