Creating folders with sub folders

I’m a graphic designer, new to applescripting, automator, etc. and am looking for a little advice.

We’re a mac based Advertising agency, all on Tiger.

I need to figure out a way to run a script or automate making folder sets.

Below is an example of one set I want users to be able to automatically generate:

Folder:
Portfolio

Subfolders:
Television
Radio
Print Outdoor
Direct Marketing
Nontraditional
Collateral
Identity
Environmental
Packaging
Interactive

I’ve been able to make a script with scripteditor, as well as automator that does this, but it won’t work on other peoples machines. It’s specific to my machine.

Can anyone help me sove this problem?

Ideally what i would like to do is make a bunch of these scripts that make folder sets, and make an application that allows you to pick what type of folder set you would like to create, and have it automatically generated.

Can anyone point me in the right direction.

Thanks,

(apologies for any terminology i used incorrectly)

Paul

Model: G5
AppleScript: 2.1.1 i think
Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

Hi Paul,

You don’t say if you want the user to be able to choose where the folders are added. If it is to a particular folder (like the Desktop) you can set a generic ‘path to’ - see the Standard Additions scripting dictionary> File Commands> Path To.

Take a look at this script:

-- List of top level folder names.
set typeList to {"Portfolio", "type 2", "type 3"}
-- Choose from this list.
set folderType to (choose from list typeList with prompt "Which folder set do you want?") as text
-- Depending on the answer choose a sub folder list.
if folderType is "Portfolio" then
	set subList to {"Television", "Radio", "Print Outdoor", "Direct Marketing", "Nontraditional", "Collateral", "Identity", "Environmental", "Packaging", "Interactive"}
else if folderType is "type 2" then
	set subList to {"sub 1", "sub 2", "sub 3"}
else if folderType is "type 3" then
	set subList to {"sub 4", "sub 5", "sub 6"}
end if
-- Choose where you want the folders put.
set myPath to (choose folder with prompt "Where do you want the set made?") as text
-- Make the folders with the Finder.
tell application "Finder"
	make new folder at folder myPath with properties {name:folderType}
	repeat with mySub in subList
		make new folder at folder ((myPath & folderType & ":") as text) with properties {name:mySub}
	end repeat
end tell

You’ll need to change the names of the top level and sub folder names to fit your needs. Also some error checking for cancelled dialogs.

John M

John,

Thats awesome. That’s what i was looking to do. I think i like giving the user the option of deciding where they want to make the folders, instead of setting a default location. Is that what you were asking?

I’ll change the names and screw around with it a bit.

Could i email you if i run into some problems?

Thanks man!

Paul

Hi Paul,

If you have any problems changing things around etc., just post back here.

Best wishes

John M

John,

I’m hoping to set up custom folder sets for different jobs, like print, broadcast, interactive etc. It look like you set me up to do that. Down the road, will i be able to set it up to include files as well?

We have newsletters that we do every month here, and we always end up navigating to the previous months job and collecting the files we need to work with. Is there a way I could set up a custom folder set in this thing that includes template files, font folders, etc?

That would save us a bunch of time in the long run.

Thanks,

Paul

You could use the script John M submited to create the folder structure. Then populate the folders and subfolders with the templates and common files and save it on you computer or server. When you get a job in that uses this setup just duplicate the top level folder using “command D” in the finder (all the subfolders and files will be dupllicated too).

CarbonQuark

Thanks CarbonQuark,

That would work, but it’s not to far from what we’re doing now.
I think we’ll set this up as an initial step though.

If it’s possible, it would be ideal if we could get a script to do this.

I’m at an ad agency, and what I’m hoping to do, is develop this script so that the Account Executives and their assistants can make job folders for us prior to us recieving the job tickets. That way when we start working on the job, a lot of the monkey work has been done for us, so we can just go to the folder and start work. If we had them navigate to a template folder, duplicate a folder set, and place them in a job folder for us, they would probably get confused and raise hell about all the extra work they have to do.

Thanks

pdax

I’m new to this forum and was looking for some help but I fist have to say…

Great Post guys I was just looking for some thing simular to this, I also found somthing useful in this thread:

http://bbs.applescript.net/viewtopic.php?pid=40602

But I’d like to know if there is any way to use what you have made here and add say a pop up dialoge that will ask for the user to enter the name of the folder and then a Prefix to add to the front of the parent folder and all it’s subfolders?

what is being created: Parent folder, subfolders: PDF, QXD, PSD, AI, WEB

Example:

Prompt for Parent Folder name: ProjectX

Prompt for Prefix: PX-1275- (used for parent and sub folders)

Result:

PX-1275-ProjectX
PX-1275-PDF
PX-1275-PSD
PX-1275-QXD
PX-1275-AI
PX-1275-WEB

I’m just trying to figure out a way to organize things and have folders auto created with a job prefix. I think you guys have somthing very close to what I’m looking for but I’d like to know how to tie it together.

Any help?
Thanks in advance.

Hi Racoon,

With the script above you are 90% of the way to what you want.

Take

-- Choose where you want the folders put.
set myPath to (choose folder with prompt "Where do you want the set made?") as text
-- Make the folders with the Finder.
tell application "Finder"
	make new folder at folder myPath with properties {name:folderType}
	repeat with mySub in subList
		make new folder at folder ((myPath & folderType & ":") as text) with properties {name:mySub}
	end repeat
end tell

and before this, add a couple of dialogs asking for the job name and the prefix and make your sub folders into a list and you’re there.

Post back with what you have if you need more help.

Best wishes

John M

Hi, Raccoon. This isn’t the same method as John’s, but the result’s pretty similar. It uses a single Unix ‘mkdir’ command instead of a repeat in the Finder:

-- Prompt for a prefix.
set prefix to text returned of (display dialog "Please choose a prefix for the project folder names." default answer "PX-1275-" with icon note)
if prefix does not end with "-" then set prefix to prefix & "-"

-- Use a "Save as." dialog to set the name and location for this project folder.
set parentFolder to (choose file name with prompt "Save the project folder as." default name (prefix & "Project name"))
set parentPosix to quoted form of POSIX path of parentFolder

-- Assemble the mkdir command.
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ""
set mkdirStr to {"mkdir -p ", parentPosix, "/", prefix, "{PDF,PSD,QXD,AI,WEB}"} as Unicode text
set AppleScript's text item delimiters to astid

-- Create the folders.
do shell script mkdirStr

-- tell application "Finder" to open parentFolder

I ran into a similar project a while back, and had to develop a project to make folder structures on 2 different different servers each with their own unique folder structure.
I went with the shell script: "do shell script (“mkdir -p”), I found it just a few seconds faster than “make new folder”
I also added in a feature from another script that will flush out all illegal characters as well as spaces and replace them with an underscore:
So if user inputs “XXXX XXXX 12$65”, the script will create “XXXX_XXXX_12_65”

I got alot of help from these forums to make this script happen, so here’s my compiled code

on run

--Make a choice for server folder type--
display dialog ¬
	"What server folder do you need to make" buttons {"AD", "PrePress", "Cancel"}
set the button_pressed to the button returned of the result

--To make  AD server--
if the button_pressed is "AD" then
	
	set destination_ to (choose folder with prompt "Choose a destination for the job folder.") as string
	set dd to (display dialog "Enter Your Job Number." default answer "XXXX_XXXX_12345")
	set jobName to text returned of dd
	set prefix_ to text -5 thru end of jobName & "_"
	set subfolder_names to prefix_ & "{Old_QXD,ILL_EPS,PSD,Resources,EPS_TIF}" -- no spaces 
	set transmission_names to prefix_ & "Transmissions/{In,Out}" -- no spaces 
	
	set replace_strings to ¬
		{" ", "  ", "-", "_", "__", "~", "`", ":", ";", "!", "@", "â„¢", "'", "®", "#", "$", "?", "<", ">", "%", "^", "&", ¬
			"*", "(", ")", "=", "+", "{", "}", "[", "]", "|", "\\", "/", "'", ",", "\""}
	set astid to AppleScript's text item delimiters
	repeat with this_replace_string in replace_strings
		set jobName to my FixName(jobName, (contents of this_replace_string))
	end repeat
	set AppleScript's text item delimiters to astid
	
	set jobFolderPOSIX to POSIX path of (destination_ & jobName) & "/"
	
	do shell script ("mkdir -p " & jobFolderPOSIX & subfolder_names)
	
	do shell script ("mkdir -p " & jobFolderPOSIX & transmission_names)
	tell application "Finder" to update folder destination_
	
	
	--To make PrePress server--
else if the button_pressed is "PrePress" then
	set destination_ to (choose folder with prompt "Choose a destination for the job folder.") as string
	set dd to (display dialog "Enter Your Internal Job Number." default answer "XXXX_XXXX_12345")
	set fcbName to text returned of dd
	set prefix_ to text -5 thru end of fcbName & "_"
	set par to (display dialog "Enter The Client Job Number" default answer "XXXXXX")
	set clientCode to text returned of par
	set holdingfolder_names to prefix_ & "Holding/{Old,CompArt,Transmissions}"
	
	set replace_strings to ¬
		{" ", "  ", "-", "_", "__", "~", "`", ":", ";", "!", "@", "â„¢", "'", "®", "#", "$", "?", "<", ">", "%", "^", "&", ¬
			"*", "(", ")", "=", "+", "{", "}", "[", "]", "|", "\\", "/", "'", ",", "\""}
	set astid to AppleScript's text item delimiters
	repeat with this_replace_string in replace_strings
		set fcbName to my FixName(fcbName, (contents of this_replace_string))
		set clientCode to my FixName(clientCode, (contents of this_replace_string))
	end repeat
	set AppleScript's text item delimiters to astid
	
	set fcbFolderPOSIX to POSIX path of (destination_ & fcbName) & "/"
	
	do shell script ("mkdir -p " & fcbFolderPOSIX & clientCode & "/" & holdingfolder_names)
	
	tell application "Finder" to update folder destination_
	
else
	quit
end if

end run

on FixName(currentName, fixString)
set AppleScript’s text item delimiters to fixString
set listName to every text item of currentName
set AppleScript’s text item delimiters to “_”
return (listName as string)
end FixName

Wow, thanks so much guys I gota all the help I needed from this forum, it was hard enough trying to find it out on the net, you guys are great.

I used the script that Nigel Garvey suggested to make a small app that the Account guys can use to set up the job folders. It’s a no brainer at that point they just have to put the files where they belong and delete folders they know they don’t need. Makes it easier than to have to trust them with the responsability of actually remembering to make folders as aposed to just dropping a bunch of files in 1 folder and saying “uh…yeah it’s all in there…” I poped it on the server and had them make an Alias to it so I can Update it if I have to with out rocking their little world. :slight_smile:

Thank you all for your contributions.
-Happy- Raccoon :smiley: too bad they don’t have a raccoon smiley.

PS. Any one know how to mass substitute a character for another? Here’s what I mean. I’m trying to make our Mac network and System more Universal and PC friendly for our new web staff, and I did a search for all files and folders on the server that have “/” in them, now that I have them I’d like to change them all to a “-” any quick way of doing that rather than editing the names of each file or folder by hand?

Thanks again for the help with this. I’m back on the project and could use a little more help. I’m still trying to work on generating new folder sets, I guess i’m hoping someone can help me figure out how to make additional levels of subfolders.

If you can show me the code for going levels down, i should be able to figure it out for subsequent folders.

Need to set up the following structure for a New Client Folder:

Account Service
Admin
Billing
Memos
Miscellaneous
Status Reports
Completed Projects
Media
Projects
Resources
Logos
Miscellaneous
Photography
Templates
Strategy
Background
Planning
Research

-- List of top level folder names.
set typeList to {"New Client", "Portfolio", "Print", "Broadcast", "Interactive"}
-- Choose from this list.
set folderType to (choose from list typeList with prompt "Which folder set do you want?") as text
-- Depending on the answer choose a sub folder list.
if folderType is "New Client" then
	set subList to {"Account Service", "Completed Projects", "Media", "Projects", "Resources", "Strategy"}
else if folderType is "Print" then
	set subList to {"proofs", "concepts", "working"}
else if folderType is "Collateral" then
	set subList to {"proofs", "concepts", "working"}
else if folderType is "Portfolio" then
	set subList to {"Television", "Radio", "Print Outdoor", "Direct Marketing", "Nontraditional", "Collateral", "Identity", "Environmental", "Packaging", "Interactive"}
end if
-- Choose where you want the folders put.
set myPath to (choose folder with prompt "Where do you want the set made?") as text
-- Make the folders with the Finder.
tell application "Finder"
	make new folder at folder myPath with properties {name:folderType}
	repeat with mySub in subList
		make new folder at folder ((myPath & folderType & ":") as text) with properties {name:mySub}
	end repeat
end tell

Model: G5
Browser: Firefox 1.5.0.1
Operating System: Mac OS X (10.4)

Hi pdax,

It seems to me that it would be easier to make an outline and just create your folders from that outline. I’ll make an example.

BRB,

Hi,

Sorry about the delay. I was thinking of the best approach to this and fell asleep. Here’s what I came up with just now:

set t to “Main
Sub1
Subsub1
Subsub2
Sub2
Sub3
Subsub1
Subsubsub1
Sub4”
set file_paths to {}
set pop_list to {}
set p_list to paragraphs of t
repeat with this_p in p_list
set o to (offset of (first word of this_p) in this_p)
repeat until (count pop_list) < o
set pop_list to reverse of rest of reverse of pop_list
end repeat
set this_string to (text o thru -1 of this_p)
set end of pop_list to this_string
set def_tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “:”
set this_path to pop_list as string
set AppleScript’s text item delimiters to def_tid
set end of file_paths to this_path
end repeat
return file_paths

Another easy way, but rquires some work is to create a folder structer manually in the Finder. Then when you want to create a folder you just duplicate the folder that is already made. Perhaps you could run the above script (with modifications) when you want to create a modified template. Then when you want a clients folder you just duplicate the template.

gl,

No problem Kel, I’m just glad you guys are willing to help out.

So I tried running the script, but i can’t get it to work. I’m guessing I’m doing something wrong.

What I was doing with the other script was saving it as an application.

Our Account Execs will be using this when they start a project so they can build us template folder sets for different jobs.

My only fear is that if it isn’t as simple as opening an app, selecting a project type, and saving it in a client folder, they’ll either get confused or mess something up.

Hi pdax,

The script doesn’t do anything. It’s just an example you can run in the Script Editor and look at the result. It’s easy to modify it to make folders.

While I was trying to go back to sleep to find that beautiful woman who kissed me, I thought of some fixes. You could create your outline with Word or something using leading tabs and save as text document. Then your script could read this file and make the folders.

I’ll fix it up a little.

gl,

Hi pdax,

What I did was create this outline in TextEdit named “New Client.txt”, because Word was adding extra formating to the leading tabs.

New Client
Account Service
Admin
Billing
Memos
Miscellaneous
Status Reports
Completed Projects
Media
Projects
Resources
Logos
Miscellaneous
Photography
Templates
Strategy
Background
Planning
Research

I saved this file into a new folder on my desktop named “Folder Templates”. I also saved the following script as application in the same folder.

property folder_refs : {} – for later use in syncing

– set folder_path to (choose folder) as string
set my_ref to (path to me)
tell application “Finder”
set folder_path to (container of my_ref) as string
end tell
set f to (folder_path & “New Client.txt”) as alias
set t to read f
set pop_list to {folder_path}
set folder_refs to {}
set p_list to paragraphs of t
repeat with this_p in p_list
set o to (offset of (first word of this_p) in this_p)
set pop_list to (items 1 thru o of pop_list)
set def_tid to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “:”
set this_path to pop_list as string
set AppleScript’s text item delimiters to def_tid
set this_name to (text o thru -1 of this_p)
set end of pop_list to this_name
tell application “Finder”
set new_folder to (make new folder at (this_path as alias) with properties ¬
{name:this_name})
end tell
set end of folder_refs to (new_folder as alias)
end repeat

When this scirpt app is run it gets a reference to it’s containing folder. It then gets the outline file and reads the outline. Then folders are made. You can try to make it more efficient with the advice of the other posters. You should try to add error checking after you’ve learned more AppleScript and expand it.

gl,

Thanks for helping me out.
I’ll mess around this and see for what i can do

Hi pdax,

You’re welcome. I made another fix. The script was working, but the folder paths were improperly formed and coercion was correcting it.

property folder_refs : {} – for later use in syncing

– set folder_path to (choose folder) as string
set my_ref to (path to me)
tell application “Finder”
set folder_path to (container of my_ref) as string
end tell
set f to (folder_path & “New Client.txt”) as alias
set t to read f
set pop_list to {folder_path}
set folder_refs to {}
set p_list to paragraphs of t
repeat with this_p in p_list
set o to (offset of (first word of this_p) in this_p)
set pop_list to (items 1 thru o of pop_list)
set this_path to pop_list as string
set this_name to (text o thru -1 of this_p)
set end of pop_list to (this_name & “:”)
tell application “Finder”
set new_folder to (make new folder at (this_path as alias) with properties ¬
{name:this_name})
end tell
set end of folder_refs to (new_folder as alias)
end repeat

gl,