So I have a droplet app i am working on to be able to drop a project folder, choose from a list which folders I would like to create in that directory, and create them from the selections in that list. Working no problem:
on open {dropped_folder}
set project_folder to alias dropped_folder
set folderList to {"maya", "nuke", "ae", "ai", "psd", "fcp", "concept", "archive", "footage", "renders"}
set folder_selection to choose from list folderList with prompt "Create folders for:" with multiple selections allowed
tell application "Finder"
repeat with currentValue in folder_selection
make new folder at project_folder with properties {name:currentValue as string}
end repeat
end tell
end open
What I want to be able to do though, is have all of those folders already created with custom icons. I am guessing the best way to do this is to just create folders with all the proper icons in my Users/Application Support directory, and duplicate the folders from their into the new path.
The problem though, is how do I only duplicate the folders set in: folder_selection ? The above script creates new folders with all the proper names from the list selection but being able to just duplicate them from a specified path would be ideal.
I have another method for re-iconing the folders but it would be great to avoid that step.
Thanks!
Hi,
I wrote you a small sample script, which should get you started.
The template folders are supposed to be located in the script’s application support folder, e.g. if the mytitle variable is “Projectomat”, then the script will search for template folders in
~/Library/Application Support/Projectomat/
You might also be interested in subidoo.
Best regards from rainy Berlin,
Martin
property mytitle : "Sample Script"
-- I am called when the user starts the script with a doubleclick
on run
set projectfolder to choose folder with prompt "Please choose a project folder:" without multiple selections allowed
open {projectfolder}
end run
-- I am called whener a user drops FInder items onto the script's icon
on open finderitems
try
-- searching for folders
set projectfolders to {}
repeat with finderitem in finderitems
set finderiteminfo to (info for finderitem)
if folder of finderiteminfo then
set projectfolders to projectfolders & finderitem
end if
end repeat
-- no folders found
if projectfolders is {} then
set errmsg to "We could not find any folders in the dropped items."
my dsperrmsg(errmsg, "--")
return
end if
-- processing each found folder
repeat with projectfolder in projectfolders
set {success, errmsg} to my procprojectfolder(projectfolder)
if success is false then
set errmsg to ("Processing the follwoing folder returned an error:" & return & return & projectfolder as text) & return & return & errmsg
my dsperrmsg(errmsg, "--")
end if
end repeat
on error errmsg number errnum
if errnum is not equal to -128 then
my dsperrmsg(errmsg, errnum)
end if
end try
end open
-- I am processing a single project folder
on procprojectfolder(projectfolder)
try
-- which folders should be created?
set foldernames to my askforfoldernames()
if foldernames is missing value then
return {true, missing value}
end if
-- this folder contains the folder templates
set appsuppfolderpath to (((path to application support folder from user domain) as text) & mytitle & ":")
if not my itempathexists(appsuppfolderpath) then
set errmsg to "The folder containing the folder templates does not exist:" & return & return & appsuppfolderpath
error errmsg
end if
-- duplicating the templates to the project folder
set qtdprojectfolderpath to quoted form of POSIX path of (projectfolder as text)
repeat with foldername in foldernames
set templatefolderpath to appsuppfolderpath & foldername & ":"
if not my itempathexists(templatefolderpath) then
set errmsg to "The template folder does not exist:" & return & return & templatefolderpath
error errmsg
end if
set qtdtemplatefolderpath to quoted form of POSIX path of templatefolderpath
if character -2 of qtdtemplatefolderpath is "/" then
set qtdtemplatefolderpath to ((characters 1 through -3 of qtdtemplatefolderpath) & "'") as text
end if
set command to "cp -r " & qtdtemplatefolderpath & " " & qtdprojectfolderpath
do shell script command
end repeat
return {true, missing value}
on error errmsg number errnum
return {false, errmsg}
end try
end procprojectfolder
-- I am asking the user to choose from a list of foldernames
on askforfoldernames()
set foldernames to {"maya", "nuke", "ae", "ai", "psd", "fcp", "concept", "archive", "footage", "renders"}
choose from list foldernames with prompt "Create folders for:" with title mytitle OK button name "Choose" cancel button name "Quit" with multiple selections allowed without empty selection allowed
set usrchoice to result
if usrchoice is not false then
set chosenfoldernames to (usrchoice as list)
return chosenfoldernames
else
return missing value
end if
end askforfoldernames
-- I am indicating if a given item path exists
on itempathexists(itempath)
try
set itemalias to itempath as alias
return true
on error
return false
end try
end itempathexists
-- I am displaying error messages to the user
on dsperrmsg(errmsg, errnum)
tell me
activate
display dialog "Sorry, an error occurred:" & return & return & errmsg & " (" & errnum & ")" buttons {"OK"} default button 1 with title mytitle with icon stop
end tell
end dsperrmsg
Hi.
At its simplest, something like this:
on open {dropped_folder}
set project_folder to dropped_folder
set folderList to {"maya", "nuke", "ae", "ai", "psd", "fcp", "concept", "archive", "footage", "renders"}
set folder_selection to (choose from list folderList with prompt "Create folders for:" with multiple selections allowed)
if (folder_selection is false) then error number -128
set project_template to ((path to application support from user domain as Unicode text) & "Project Template:") as alias -- Use your own template name and location here.
tell application "Finder"
duplicate (folders of project_template whose name is in folder_selection) to project_folder
end tell
end open
Cool thanks a lot everyone! Should get me there.
I learned a lot by looking through your script Martin very much appreciated.
EDIT: Got it! Thanks again, I am going the simpler route but thanks again Martin for all the great info. Really appreciate it Nigel, I new there had to be a simple way to duplicate only the items from a list just couldn’t find the right syntax.