Character correction

I’m new to AppleScripting, so be gentle with me please :slight_smile:

I’ve been searching the forums and can’t find anything to help me with this problem. I’ve made a script to make a set of folders for a job, and we have a strict naming convention where the folders need to be named with upper case characters (except for the last short name part) and have no spaces. Also the last short name should only be 6 characters or less. What I would like it to do is for the script to change any lower case letters in the “FILM_NAME” to upper case, and substitute spaces for “", and in the short name to substitute any upper case letters to lower case, replace spaces with "” and delete any characters after the first 6.

Here’s the code I have for the folder creation:

tell application "Finder"
	set JobName to text returned of (display dialog "Please enter film title:" default answer "FILM_TITLE")
	set ShortCode to text returned of (display dialog "Please enter film short name (6 characters or less):" default answer "title")
	
	set loc to choose folder "Choose Parent Folder Location"
	set newfoldername to JobName
	set newfo to make new folder at loc with properties {name:newfoldername}
	make new folder at newfo with properties {name:newfoldername & "_STYLEGUIDE"}
	make new folder at newfo with properties {name:newfoldername & "_SUPPLIED"}
	make new folder at newfo with properties {name:newfoldername & "_TERRITORIES"}
	set design to make new folder at newfo with properties {name:newfoldername & "_DESIGN"}
	set filmshortname to ShortCode
	set gen to make new folder at design with properties {name:newfoldername & "_OLD"}
	set gen to make new folder at design with properties {name:"GEN_XXXXXX_XXSEA_" & filmshortname}
	make new folder at gen with properties {name:"ART"}
	make new folder at gen with properties {name:"FONTS"}
	make new folder at gen with properties {name:"IMAGES"}
	make new folder at gen with properties {name:"LAYERED_IMAGES"}
	make new folder at gen with properties {name:"RENDERS"}
	set design to make new folder at newfo with properties {name:newfoldername & "_GENERIC"}
	set gen to make new folder at design with properties {name:"GEN_XXXXXX_XXSEA_" & filmshortname}
	make new folder at gen with properties {name:"ART"}
	make new folder at gen with properties {name:"FONTS"}
	make new folder at gen with properties {name:"IMAGES"}
	make new folder at gen with properties {name:"LAYERED_IMAGES"}
end tell

Any help will be much appreciated. :smiley:

Hi,

try this


tell application "Finder"
	set JobName to text returned of (display dialog "Please enter film title:" default answer "FILM_TITLE")
	set JobName to (do shell script "/bin/echo " & quoted form of JobName & " | /usr/bin/tr a-z' ' A-Z_")
	set ShortCode to text returned of (display dialog "Please enter film short name (6 characters or less):" default answer "title")
	set ShortCode to (do shell script "/bin/echo " & quoted form of ShortCode & " | /usr/bin/tr A-Z' ' a-z_")
	if length of ShortCode > 6 then set ShortCode to text 1 thru 6 of ShortCode
	
	set loc to choose folder "Choose Parent Folder Location"
.

That’s awesome! Thanks a lot.

tell application "Finder"
	
	set JobName to text returned of (display dialog "Please enter film title:" default answer "FILM_TITLE")
	
	set JobName to (do shell script "/bin/echo " & quoted form of JobName & " | /usr/bin/tr a-z' ' A-Z_")
	set ShortCode to "title  "
	repeat until (count of characters of ShortCode) ≤ 6
		set ShortCode to text returned of (display dialog "Please enter film short name (6 characters or less):" default answer ShortCode)
	end repeat
	set ShortCode to (do shell script "/bin/echo " & quoted form of ShortCode & " | /usr/bin/tr A-Z' ' a-z_")
	
	set loc to choose folder "Choose Parent Folder Location"

Working with Stefans script.
How about limiting the characters of the short name in the first place. This will only allow 6 or less before moving on.