AppleScript or Automator?: Creating new Job folder and subfolders

Hi,
Completely newbie here but here is what I want to learn to do. For every new job I start (I am a graphic designer) I create a new Job folder with subfolders. The Main folder has a Unique name and number. The sub-folders have generic labels that every job has, but with the unique job folder in front of the label. It looks like this:

00000_Job Name
00000_Layouts
00000_PDF proofs
00000_Client docs
00000_Final to printer
00000_Art
00000_Printer quotes

What I want to do is create an applet or folder action or automator action that duplicates these folders and asks me for the job number to replace the "00000"s with the unique job number. So I would end up with:

06358_New CocaCola Logo
06358_Layouts
06358_PDF proofs
06358_Client docs
06358_Final to printer
06358_Art
06358_Printer quotes

This may seem like a roundabout way of duplicating a folder and just pasting the number in each subfolder, but sometimes I have to work fast and create several jobs in a day. When I don’t create all these folders, I end up with too many files floating around. Also, my colleagues would use the same naming convention and it’s easier to work with each other’s jobs this way.

Thanks for your VERY BASIC explanation if this is possible and what is the simlest method.

JC

Hi JC,

one possible solution is, to create the main folder, name it and drag it onto this droplet:

on open theseFolders
	repeat with theFolder in theseFolders
		set {folderFlag, JobNumber} to {folder, text 1 thru 5 of name} of (info for theFolder)
		if folderFlag then
			set FolderNameList to {"_Layouts", "_PDF proofs", "_Client docs", "_Final to printer", "_Art", "_Printer quotes"}
			tell application "Finder"
				repeat with i from 1 to count FolderNameList
					make new folder at theFolder with properties {name:JobNumber & item i of FolderNameList}
				end repeat
			end tell
		end if
	end repeat
end open

Just save the script as application. It works also dragging multiple folders onto it

I might as well post this also. You enter the name an number through dialog:


property subf_names : {"Layouts", "PDF proofs", "Client docs", "Final to printer", "Art", "Printer quotes"}
--
display dialog "Enter job name:" default answer "job name"
set j_name to text returned of result
repeat
	display dialog "Enter job number:" default answer "0"
	set j_number to text returned of result
	try
		if (j_number as integer) < 100000 and ¬
			(j_number as integer) > -1 then exit repeat
	on error
		display dialog "Error: enter an integer less than 100,000."
	end try
end repeat
set job_number to text -6 thru -1 of ("0000" & j_number & "_")
set temp_name to job_number & j_name
tell application "Finder"
	set main_folder to (make new folder at desktop with properties {name:temp_name}) as alias
	repeat with this_name in subf_names
		set temp_name to job_number & this_name
		make new folder at main_folder with properties {name:temp_name}
	end repeat
end tell

Places the main folder on the desktop. it will quit and error if there is a folder with the same name.

gl,

While the above solutions are excellent, don’t forget to check out Client Folder Maker too! :smiley:

excellent solutions all! It would have taken me a long time to figure this out, since I don’t know AppleScript, but this way I can learn in reverse by deconstructing the script.

Thanks all.

JC

this is an older post, i know. i just wanted to share my first successful attempts at goofing with applescripts. hopefully these will come to some use to somebody other than me.

many thanks to kel for his script. all i did was make some changes to it to fit our offices a little bit better. now it asks which client we are making the job for, and defaults to the folder that has all of our clients:



property subf_names : {"proofs", "images", "finals"}
--
display dialog "What's the job name?" default answer "junk"
set j_name to text returned of result
repeat
	display dialog "Enter job number:" default answer "0"
	set j_number to text returned of result
	try
		if (j_number as integer) < 100000 and ¬
			(j_number as integer) > -1 then exit repeat
	on error
		display dialog "Error: enter an integer less than 100,000."
	end try
end repeat
set job_number to text -6 thru -1 of ("_" & "0000" & j_number)
set temp_name to j_name & job_number
tell application "Finder"
	
	set whereToCreate to choose folder with prompt "Which client is purchasing this job?" default location ("/Volumes/Deimos/Clients" as POSIX file)
	set main_folder to (make new folder at whereToCreate with properties {name:temp_name}) as alias
	set thisFolderPath to (whereToCreate as string) & temp_name & ":"
	if not (exists folder thisFolderPath) then make new folder at whereToCreate with properties {name:thisFolderName}
	repeat with this_name in subf_names
		set temp_name to this_name
		make new folder at main_folder with properties {name:temp_name}
	end repeat
end tell


i was also inspired to make a little script that would create those client folders with general asset sub-folders inside, and place them in the default location.

it was fun, and thanks again to all for a great site!

Model: imac 20" core 2, emac 1.0Ghz, mbp, mb
AppleScript: newest
Browser: Safari 523.15
Operating System: Mac OS X (10.5)

Hi, phospholipid.

Thanks for your post. I’m glad you’ve had fun putting it together and hope you’ll be inspired to do more AppleScripting in future.

May I suggest changing this line:

set job_number to text -6 thru -1 of ("_" & "0000" & j_number)

” to this?:

set job_number to "_" & text -5 thru -1 of ("0000" & j_number)

You want to keep the underscore character and the last five characters of whatever’s produced when you concatenate “0000” and j_number. In Kel’s script, the underscore came after the numeric characters and he decided to concatenate everything together first and get the last six characters of the combined result.

set job_number to text -6 thru -1 of ("0000" & j_number & "_")

But he could have (and perhaps should have, for clarity) sorted out the five numeric characters first and then appended the underscore:

set job_number to text -5 thru -1 of ("0000" & j_number) & "_"

Not to detract from any of the scripts above, set hierarchies make an ideal job for the Unix “mkdir” command. cordovez’s entire “06358” hierarchy could be created on the desktop with a single command:

do shell script "mkdir -p " & quoted form of POSIX path of (path to desktop) & "06358_'New CocaCola Logo'/06358_{'Layouts','PDF proofs','Client docs','Final to printer','Art','Printer quotes'}"

To modify Kel’s script to this end:

set subFolderLabels to "{'Layouts','PDF proofs','Client docs','Final to printer','Art','Printer quotes'}"

display dialog "Enter job name:" default answer "job name"
set j_name to "'" & text returned of result & "'"

repeat
	display dialog "Enter job number:" default answer "0"
	try
		set j_number to (text returned of result) as integer
		if (j_number < 100000) and (j_number > -1) then exit repeat
		error
	on error
		display dialog "Error: enter an integer between 0 and 99,999."
	end try
end repeat
set job_prefix to text -5 thru -1 of ((100000 + j_number) as text) & "_"

do shell script "mkdir -p " & quoted form of POSIX path of (path to desktop) & job_prefix & j_name & "/" & job_prefix & subFolderLabels

that’s awesome! thanks so much! i’ll look into goofing with that later this afternoon.

have a great day.

jh

I have a similar script, which is as follows:

set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
set newJobFolder to my newFold(jobNum, jobName, folderpath)
on newFold(theNumber, theName, thefolder)
	set subNameList to {"Admin", "Costings & Proposals", "Official Documents", "Print", "Schedule", "Studio", "Text & Amends"}
	tell application "Finder"
		set newJobFolder to (make new folder at thefolder with properties ¬
			{name:theNumber & " - " & theName})
		repeat with i from 1 to 9
			make new folder at newJobFolder with properties ¬
				{name:theNumber & " - " & item i of subNameList}
		end repeat
	end tell
end newFold

I would like to tweak it slightly by removing the job number and dash from the subfolders, but I have tried different amendments but to no avail. Can anyone help?

Thanks,
Mark

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

Hello

Here you are


set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
set newJobFolder to my newFold(jobNum, jobName, folderpath)
on newFold(theNumber, theName, thefolder)
	set subNameList to {"Admin", "Costings & Proposals", "Official Documents", "Print", "Schedule", "Studio", "Text & Amends"}
	set itemCount to count of subNameList
	tell application "Finder"
		set newJobFolder to (make new folder at thefolder with properties ¬
			{name:theNumber & " - " & theName})
		repeat with i from 1 to itemCount
			make new folder at newJobFolder with properties ¬
				{name:"" & item i of subNameList}
		end repeat
	end tell
end newFold

Best Regards

McUsr

Thanks McUsr,

Works a treat. Now, how would you add subfolders to subfolders? i.e. the main job folder holds the subfolder “Text & Amends” and inside the “Text & Amends” subfolder there are two sub-subfolders, a “Text” folder and an “Amends” folder.

Thanks in advance,

Mark

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

Hello
Here you are :slight_smile:



set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to (choose folder with prompt "Select client folder")
set newJobFolder to my newFold(jobNum, jobName, folderpath)
on newFold(theNumber, theName, thefolder)
	set subNameList to {"Admin", "Costings & Proposals", "Official Documents", "Print", "Schedule", "Studio", "Text & Amends"}
	set itemCount to count of subNameList
	tell application "Finder"
		set newJobFolder to (make new folder at thefolder with properties ¬
			{name:theNumber & " - " & theName})
		repeat with i from 1 to itemCount
			set thisFolder to make new folder at newJobFolder with properties ¬
				{name:"" & item i of subNameList}
			if item i of subNameList contains "Text & Amends" then
				make new folder at thisFolder with properties ¬
					{name:"Text"}
				make new folder at thisFolder with properties ¬
					{name:"Amends"}
			end if
			
		end repeat
	end tell
end newFold

Best Regards

McUsr

Hi,

to create a bunch of folders and subfolders I prefer always the mkdir method


set jobNum to text returned of (display dialog "Enter a job number:" default answer "")
set jobName to text returned of (display dialog "Enter a job name:" default answer "")
set folderpath to POSIX path of (choose folder with prompt "Select client folder")
do shell script "/bin/mkdir -p " & quoted form of folderpath & "/" & ¬
	quoted form of (jobNum & " - " & jobName) & "/{Admin,'Costings & Proposals','Official Documents',Print,Schedule,Studio,'Text & Amends'/{Text,Amends}}"


Hello.

Stefan’ s solution is much faster than mine, I just created it for you in a hurry (but tested it).

You should really use his solution.

Best Regards

McUsr

Thanks both of you.

Stefan, I can’t get yours to work, it gives me the following error message:

Syntax Error
Expected string but found end of script.

Can you help with the error?

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

Maybe the next line character (¬) is misinterpreted

Hi Stefan,

That works now.

Thank you so much for your help!

And thank you McUsr too!

Mark

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

Guys,
I have, hopefully, just one more question.

What do you do in order to get the applescript useable on, dare I say it, Windows XP?

Thanks in advance,

Mark

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

Okay, another question!

I need to add folders inside other folders, which you showed me, but when I try to amend it to add folders myself, it doesn’t work properly i.e. my results are fine on the main folder, but the subfolders seem to show part of the Applescript string e.g. {Admin,Costings & Proposals.

How do I fix this?

Thanks in advance,

Mark
(Useless Applescripter)

Model: MacBook Pro
AppleScript: 2.1.2
Browser: Safari 533.16
Operating System: Mac OS X (10.6)

First . you remove Windows XP :smiley:

Sorry couldn’t help it. You have to rewrite it into whatever. If you install Cygwin you should be able to use what Stefan had inside of his do shell script command in the post above. I don’t know more than that. And that you must ensure that Cygwin uses the Bash command line interpreter. (Bourne Again Shell).

The solution is of course to get rid of Windows. :wink:

Best Regards

From the humorous McUsr