Adding subfolders to this scripts

I am completly new to writing scripts. I was givien a great script for use with final cut pro. It creates a set of folders based on the name you give the project. I would like to modify this script to include subfolders within subfolders. For example, in the the media subfolder I would like to create a capture scratch folder, a Visual Effects folder, and other QuickTimes.

Also, if at all possible I would like to set custom icons to these subfolders.

set the SubFolderList to {"Project Files", "Media", "Audio", "Images", "graphics", "DVD"}
set the MasterFolderName to text returned of ¬
	(display dialog "Project name" default answer "")
set the MasterFolderHome to choose folder
set the MasterFolder to makefolder(MasterFolderHome, MasterFolderName)

repeat with subFolder in SubFolderList
	makefolder(MasterFolder, (MasterFolderName & " " & subFolder))
end repeat

to makefolder(here, what)
	tell application "Finder"
		set the newFolder to ¬
			(make new folder at here with properties {name:what})
	end tell
	return newFolder
end makefolder

Something like this, perhaps:


set the SubFolderList to {"Project Files", "Media", "Audio", "Images", "graphics", "DVD"}
property MediaSubFolderList : {"Scratch", "Visual Effects", "QuickTimes"}
property AudioSubFolderList : {"AudioScratch", "iTunes"}
property ImagesSubFolderList : {"TIFFs", "JPEGs", "PNGs"}
set the MasterFolderName to text returned of ¬
	(display dialog "Project name" default answer "")
set the MasterFolderHome to choose folder
set the MasterFolder to makefolder(MasterFolderHome, MasterFolderName) as alias

repeat with subFolder in SubFolderList
	set outerF to makefolder(MasterFolder, (MasterFolderName & " " & subFolder)) as alias
	if contents of subFolder is "Media" then
		makeSubFolder(outerF, MediaSubFolderList)
	else if contents of subFolder is "Audio" then
		makeSubFolder(outerF, AudioSubFolderList)
	else if contents of subFolder is "Images" then
		makeSubFolder(outerF, ImagesSubFolderList)
	end if
end repeat

to makefolder(here, what)
	tell application "Finder"
		set the newFolder to ¬
			(make new folder at here with properties {name:what})
	end tell
	return newFolder
end makefolder

to makeSubFolder(here, whatSet)
	repeat with subSub in whatSet
		my makefolder(here, contents of subSub)
	end repeat
end makeSubFolder

Just wondering how you could add more levels of subfolders.
I am trying to figure out the logic involved and get stuck. When the “MediaSubFolder” items get made, I’m not able to figure out how to redirect the makesubfolder function to those items so I can make folders in those items. The closest I can figure is to add logic in the function, but that seems clumsy. I’d love to make the function run “clean”.

Here’s my version…the comments in the middle were logic/commments I was playing with.



property MasterFolderName : "Default"
property subFolderName : "Default"

set the SubFolderList to {"Projects", "Media", "Post_Audio_PT", "Finishing"}

set the MediaSubFolderList to {"Audio", "GFX", "Rename_Disk_001"}
set the AudioSubFolderList to {"Tracks", "Music", "SFX"}
set the FinishingSubFolderList to {"Act_1", "Act_2", "Act_3", "Act_4", "Act_5", "Act_6", "Act_7", "Act_8"}
set the PostAudioPTSubFolderList to {"Act_1", "Act_2", "Act_3", "Act_4", "Act_5", "Act_6", "Act_7", "Act_8"}

set the TracksSubFolderList to {"Scratch", "VO_Tracks"}
set the GFXSubFolderList to {"Animation", "Stills", "AE_Projects"}

set the MasterFolderName to text returned of ¬
	(display dialog "Project name" default answer "")
set the MasterFolderHome to choose folder with prompt "Choose place to put project folder"

--Make Master Folder
set the MasterFolder to makefolder(MasterFolderHome, MasterFolderName) as alias

--Make Main SubFolders
repeat with subFolder in SubFolderList
	set mainSF to makefolder(MasterFolder, (MasterFolderName & "_" & subFolder)) as alias
	
	if contents of subFolder is "Media" then
		makeSubFolder(mainSF, MediaSubFolderList)
		
		--set subSubFolder as (path to folder Audio) in (path to folder Media) in mainSF as alias
		--set thePOSIX to POSIX path of ((path to mainSF as Unicode text) & "Audio")
		--set theAlias to POSIX file thePOSIX as alias
		--makeSubFolder(theAlias, AudioSubFolderList)
		
		--	set path to folder "GFX" as alias
		--	makeSubFolder(mainSF, GFXSubFolderList)
		
		--	set path to folder "Tracks" as alias
		--	makeSubFolder(mainSF, TracksSubFolderList)
		
	else if contents of subFolder is "Post_Audio_PT" then
		makeSubFolder(mainSF, PostAudioPTSubFolderList)
	else if contents of subFolder is "Finishing" then
		makeSubFolder(mainSF, FinishingSubFolderList)
	end if
end repeat
--~~~~~~~~~~~~~~HANDLERS~~~~~~~~~~~~~~~~~~~~
--Makefolder handler
on makefolder(here, what)
	tell application "Finder"
		set the newFolder to ¬
			(make new folder at here with properties {name:what})
	end tell
	return newFolder
end makefolder

--MakeSubFolder handler
on makeSubFolder(here, whatSet)
	repeat with subSub in whatSet
		my makefolder(here, (MasterFolderName & "_" & contents of subSub))
	end repeat
end makeSubFolder


Hi,

minimal solution:


property acts : "Act_1,Act_2,Act_3,Act_4,Act_5,Act_6,Act_7,Act_8"
set MasterFolderName to text returned of (display dialog "Project name" default answer "")
set MasterFolderHome to choose folder with prompt "Choose place to put project folder"
set MasterFolder to quoted form of (POSIX path of MasterFolderHome & MasterFolderName)
do shell script "/bin/mkdir -p " & MasterFolder & "/{Projects,Media/{Audio/{Tracks/{Scratch,VO_Tracks},Music,SFX},GFX/{Animation,Stills,AE_Projects},Rename_Disk_001},Post_Audio_PT/{" & acts & "},Finishing/{" & acts & "}}/"

Thanks Stefan.
Not quite what I had in mind, though. I was looking for an Applescript way of doing it, as well as tagging each folder created with the project name (in case the folder accidentally gets lost). Is there a way of creating a folder level (maybe more levels) and sending those folders’ aliases to the makesubfolder function? Is the logic here out of whack?

TIA
Joe

Another minimal solution, the property folderList is a nested list of the folder structure.
The handler uses a recursive function to create the subfolders


property MasterFolderName : ""
property acts : {"Act_1", "Act_2", "Act_3", "Act_4", "Act_5", "Act_6", "Act_7", "Act_8"}
property folderList : {"Projects", "Media", {"Audio", {"Tracks", {"Scratch", "VO_Tracks"}, "Music", "SFX"}, "GFX", {"Animation", "Stills", "AE_Projects"}, "Rename_Disk_001"}, "Post_Audio_PT", acts, "Finishing", acts}
set MasterFolderName to text returned of (display dialog "Project name" default answer "")
set MasterFolderHome to choose folder with prompt "Choose place to put project folder"
tell application "Finder" to set baseFolder to make new folder at folder MasterFolderHome with properties {name:MasterFolderName}
make_folder(baseFolder, folderList)

on make_folder(subFolder, theList)
	repeat with i from 1 to count theList
		set theItem to item i of theList
		if class of theItem is list then
			make_folder(subsubFolder, theItem)
		else
			tell application "Finder" to set subsubFolder to (make new folder at subFolder with properties {name:MasterFolderName & "_" & theItem})
		end if
	end repeat
end make_folder

Thanks Stephan. This really did the trick.
I took what you have done an modified the folderlist to a more hierarchical view, in case i have to pass this on to someone else.
Here’s the code:


property MasterFolderName : ""
property SubFolderList : {"Projects", "Media", "Post_Audio_PT", "Finishing"}
property MediaFolderList : {"Audio", "GFX", "Rename_Disk_001"}
property AudioFolderList : {"Tracks", "Music", "SFX"}
property acts : {"Act_1", "Act_2", "Act_3", "Act_4", "Act_5", "Act_6", "Act_7", "Act_8"}


----------Folder Hierarchy-------------------
property folderList : ¬
	{¬
		"Projects", ¬
		"Media", ¬
		{"Audio", ¬
			{"Tracks", ¬
				{"Scratch", "VO_Tracks"}, ¬
				"Music", ¬
				"SFX"}, ¬
			"GFX", ¬
			{"Animation", "Stills", "AE_Projects"}, ¬
			"Rename_Disk_001"}, ¬
		"Post_Audio_PT", acts, ¬
		"Finishing", acts ¬
		}



set MasterFolderName to text returned of (display dialog "Project name" default answer "")
set MasterFolderHome to choose folder with prompt "Choose place to put project folder"
tell application "Finder" to set baseFolder to make new folder at folder MasterFolderHome with properties {name:MasterFolderName}
make_folder(baseFolder, folderList)



---------------Function---------------------
on make_folder(subFolder, theList)
	repeat with i from 1 to count theList
		set theItem to item i of theList
		if class of theItem is list then
			make_folder(subsubFolder, theItem)
		else
			tell application "Finder" to set subsubFolder to (make new folder at subFolder with properties {name:MasterFolderName & "_" & theItem})
		end if
	end repeat
end make_folder


Thanks again.
Joe

How could i copy a project file (a generic file located in a fixed location) to the newly created Project folder?
Bonus points for renaming it based on the project name given in the dialog.

TIA
Joe