Need help creating a 3 level subfolder

Hi there,

Need some help creating a 3rd level subfolder.

Here’s what I got:

set docket to “”
set desc to “”
set newLoc to 0

set conts to {“Approved”, “Images”, “Copy Decks”, “Reference”, “PDFs”}

set noerr to true

try
set newLoc to choose folder with prompt “Select a location for the Docket folder”
set docket to display dialog “Enter Docket number
(3-letter initial of client)(last 2-digits of year)” default answer “XXX##” buttons {“OK”, “Cancel”} default button “OK”
if the button returned of docket is “OK” then
set docket to the text returned of docket
else
set noerr to false
end if
set desc to display dialog “Enter (2-letter product or division)(number sequence)” default answer “-XX###” buttons {“OK”, “Cancel”} default button “OK”
if the button returned of desc is “OK” then
set desc to the text returned of desc
else
set noerr to false
end if

on error errmsg
set noerr to false
if not (errmsg contains “user cancel”) then display dialog errmsg
end try

if noerr then
tell application “Finder”
set newLoc to make new folder at newLoc with properties {name:((docket & " " & desc) as text)}
–set newLoc to ((docket & " " & desc) as text) as alias
repeat with i from 1 to count (conts)
make new folder at newLoc with properties {name:((item i of conts) as text)}
end repeat
make new folder at ((newLoc as string) & item -2 of conts & “:”) as string as alias with properties {name:“Fonts”}
make new folder at ((newLoc as string) & item -2 of conts & “:”) as string as alias with properties {name:“Old Mechanicals”}
make new folder at ((newLoc as string) & item -2 of conts & “:”) as string as alias with properties {name:“Retrieve”}
make new folder at ((newLoc as string) & item -2 of conts & “:”) as string as alias with properties {name:“Creative”}
make new folder at ((newLoc as string) & item -2 of conts & “:”) as string as alias with properties {name:“Old Images”}
make new folder at ((newLoc as string) & item 2 of conts & “:”) as string as alias with properties {name:“To Be Checked”}
make new folder at ((newLoc as string) & item 2 of conts & “:”) as string as alias with properties {name:“Layered”}
make new folder at ((newLoc as string) & item 2 of conts & “:”) as string as alias with properties {name:“High-Res”}
make new folder at ((newLoc as string) & item 2 of conts & “:”) as string as alias with properties {name:“Vector”}

end tell

end if

I want to create two new subfolders under “Layered” called “Psds” and “Layouts”

Thanks in advance

Hi,

the easiest way to create multilevel subfolders is to use the shell mkdir command


try
	set newLoc to choose folder with prompt "Select a location for the Docket folder"
	set {text returned:docket} to display dialog "Enter Docket number 
(3-letter initial of client)(last 2-digits of year)" default answer "XXX##" buttons {"OK", "Cancel"} default button "OK"
	set {text returned:desc} to display dialog "Enter (2-letter product or division)(number sequence)" default answer "-XX###" buttons {"OK", "Cancel"} default button "OK"
	do shell script "/bin/mkdir -p " & quoted form of POSIX path of newLoc & ¬
		(docket & "\\ " & desc) & "/{Approved,Copy\\ Decks,Images/{High-Res,Layered/{Psds,Layouts},To\\ Be\\ Checked,Vector},PDFs,Reference/{Creative,Fonts,Old\\ Images,Old\\ Mechanicals,Retrieve}}"
on error errmsg number errNum
	if errNum is not -128 then display dialog errmsg
end try

Daaaammm! Nice clean coding! Thanks Stefan! :lol:

I seem to be getting a space between “XXX##” and “-XX###” anyway to delete it so it appears as “XXX##-XX###”?

Thanks so much.

you coded the space character (" ") in this line


.
  set newLoc to make new folder at newLoc with properties {name:((docket & " " & desc) as text)}
.

just replace

(docket & "\\ " & desc)

with

(docket & desc)

I recommend to ask only for the letters and numbers (XX###) and put the hyphen in the code

(docket & "-" & desc)

:rolleyes: Wow!

Didn’t know that could work!

Best Regards

McUsr

Hi Stefan,

The script you provided me has evolved to this:

try set newLoc to choose folder with prompt "Select a location for the Docket folder" set {text returned:docket} to display dialog "Enter Docket number in the format below" default answer "KCI-X-XX-X" buttons {"OK", "Cancel"} default button "OK" set {text returned:desc} to display dialog "Enter Job Description" default answer "XXXXXXXXX" buttons {"OK", "Cancel"} default button "OK" do shell script "/bin/mkdir -p " & quoted form of POSIX path of newLoc & ¬ (docket & "-" & desc) & "/{Approved,Copy\\ Decks,Images/{High-Res,Layered/{PSDs,Layouts},To\\ Be\\ Checked,Vector},PDFs,Reference/{Creative,Fonts,Old\\ Images,Old\\ Mechanicals,Retrieve}}" on error errmsg number errNum if errNum is not -128 then display dialog errmsg end try
In the job description pop up, the user may enter a string of words. However, only the first word gets saved in the folder name. If the user enters “This is a test” as the description, only “This” gets saved. How to fix this?

Thanks for your help. It’s so much appreciated.:slight_smile:

Hi,

write quoted form of right before (docket & “-” & desc)

quoted form of (docket & "-" & desc) & "/{Approved.

Hi Stefan,

I sincerely appreciate the help you’ve provided me. If there is a way I can donate money to you let me know.

I have taken your code and tweaked it some more to fit our workflow.

However, there is another step I would like to implement and would love your help on.

So far the code is:

try
	set newLoc to choose folder with prompt "Select a location for the Docket folder"
	set {text returned:docket} to display dialog "Enter Docket number in the format below" default answer "KCI-XXX-XXXXXX" buttons {"OK", "Cancel"} default button "OK"
	set {text returned:desc} to display dialog "Enter Job Description" default answer "XXXXXXXXX" buttons {"OK", "Cancel"} default button "OK"
	do shell script "/bin/mkdir -p " & quoted form of POSIX path of newLoc & ¬
		quoted form of (docket & "-" & desc) & "/{Approved,Copy\\ Decks,Images/{High-Res,Layered/{PSDs,Layouts},To\\ Be\\ Checked,Vector},PDFs,Reference/{Creative,Fonts,Old\\ Images,Old\\ Mechanicals,Retrieve},Upload\\ to\\ PUB/Sent,Upload\\ to\\ ADPLANNER/Sent}"
on error errmsg number errNum
	if errNum is not -128 then display dialog errmsg
end try

We also want to create another folder with the same name on another server located here: /Volumes/Dropbox/KCI Pick-ups
The subfolders will include Assets, Creative Files, PDFs from Studio as well as make alias’ of Copy Decks, Upload to ADPLANNER and Upload to PUB taken from the first folder created and save those alias’ only in this second folder.

I may be rubbing the genie bottle too many times, but I hope you have some time to help me with this one.

Thank you!

{Please use AppleScript tags so folks can easily download your code and examine it. Thanks, AB}

I couldn’t test this, but try it, it uses symlinks instead of Finder alias files


property symLinkList : {"/Copy Decks", "/Upload to ADPLANNER", "/Upload to PUB"}
try
	set newLoc to choose folder with prompt "Select a location for the Docket folder"
	set {text returned:docket} to display dialog "Enter Docket number in the format below" default answer "KCI-XXX-XXXXXX" buttons {"OK", "Cancel"} default button "OK"
	set {text returned:desc} to display dialog "Enter Job Description" default answer "XXXXXXXXX" buttons {"OK", "Cancel"} default button "OK"
	do shell script "/bin/mkdir -p " & quoted form of POSIX path of newLoc & ¬
		quoted form of (docket & "-" & desc) & "/{Approved,Copy\\ Decks,Images/{High-Res,Layered/{PSDs,Layouts},To\\ Be\\ Checked,Vector},PDFs,Reference/{Creative,Fonts,Old\\ Images,Old\\ Mechanicals,Retrieve},Upload\\ to\\ PUB/Sent,Upload\\ to\\ ADPLANNER/Sent}"
	set newLocBaseFolder to POSIX path of newLoc & (docket & "-" & desc)
	set dropBoxBaseFolder to "/Volumes/Dropbox/KCI Pick-ups/" & (docket & "-" & desc)
	do shell script "/bin/mkdir -p " & quoted form of dropBoxBaseFolder & "/{Assets,Creative\\ Files, PDFs\\ from\\ Studio}"
	repeat with oneLink in symLinkList
		do shell script "ln -s " & quoted form of (newLocBaseFolder & oneLink) & space & quoted form of (dropBoxBaseFolder & oneLink)
	end repeat
on error errmsg number errNum
	if errNum is not -128 then display dialog errmsg
end try


This is fantastic Stefan.

I have one oversight on my part. My coworkers using the second volume aren’t connected to the first volume therefore the link is severed.

Can you make the Copy Decks folder originate on the 2nd volume and have a linked folder on the first volume?

Thanks so much.