creating folder names based on a couple variables

I have start of a script that I need some help finishing


set Alias1 to choose folder
set theName to text returned of (display dialog "Job Number" default answer "JobID")
set theImages to text returned of (display dialog "number of Images in catalogue Ex. 5205_112_28" default answer "10")
tell application "Finder"
	set dir_1 to make new folder at Alias1 with properties {name:theName}
	set dir_2 to make new folder at dir_1 with properties {name:"Output"}
	set dir_3 to make new folder at dir_1 with properties {name:"Trash"}
	set dir_4 to make new folder at dir_1 with properties {name:"Captures"}
	set dir_5 to make new folder at dir_1 with properties {name:"Retouch"}
	repeat with i from 1 to theImages
		make new folder at dir_4 with properties {name:(theName & (text -3 through -1 of ("00" & i)))}
	end repeat
	
end tell

set choice to choose folder with prompt "choose Page Folders" with multiple selections allowed
set thePage to text returned of (display dialog "Select Page Number" default answer "01")
tell application "Finder"
	repeat with anItem in choice
		set theName to name of anItem
		set name of folder anItem to theName & thePage
	end repeat
end tell

I need to be able to repeat the Page Folders section until all the folders in “choice” have the same name length.

Thanks in advance

How do you plan on doing that?

i.e. if choice is {oneFolder, anotherFolder}
and thePage is “01”

“oneFolder01” will allways have 4 characters fewer than “anotherFolder01”

What do you want to use to pad “oneFolder01” to get the same length as “anotherFolder01”?

In any case, I’d alter this to get some desired data before a final loop though choice.

set choice to choose folder with prompt "choose Page Folders" with multiple selections allowed
set thePage to text returned of (display dialog "Select Page Number" default answer "01")
set maxLengthOfName to 0
tell application "Finder"
	repeat with anItem in choice
		set theName to name of anItem
		set name of folder anItem to theName & thePage
		if maxLengthOfName < (length of (name of folder)) then set maxLengthOfName to (length of (name of folder))
	end repeat
end tell

This just gives me an error “Can’t make length of name of «class cfol» into type number.”

Thanks for the try it feels close. Maybe if I give you more detail…

what i’m trying to get to is something like: if the job name is 1234 and there are 123 image set ups for the job over 20 pages then I’ll end up with 123 folders is the capture folder named 1234001 to 1234123 then I want the script to let me select the first say 6 folders and add the page number to the end of the name ie 123400101 etc. and continue letting me select folders until all have a page number at the end.

This version worked for me

repeat while true
	set choice to choose folder with prompt "choose Page Folders" with multiple selections allowed
	set thePage to text returned of (display dialog "Select Page Number" default answer "01")
	set maxLengthOfName to 0
	tell application "Finder"
		repeat with anItem in choice
			set theName to name of anItem
			set name of folder anItem to theName & thePage
			if maxLengthOfName < length of (name of folder anItem as text) then
				set maxLengthOfName to length of (name of folder anItem as text)
			end if
		end repeat
	end tell
end repeat

I didn’t understand what you were saying about names having the same length. If two of your selected files have different length names, what do you want to happen?

Thanks Mike this will work. Thanks heaps. So much to learn