Let me start by saying I’m totally new to scripting - so bare with me.
What I’m trying to develop is a script that will build a very specific folder structure for me. As a photographer I find myself doing this task way to often. Basically I create a job folder and within that folder I create ‘RAW’, ‘Slelects’ and ‘Finals’ folders. So far I have this:
on run
open {(choose folder with prompt "Choose the target folder for your new job:")}
end run
on open target_folder
set target_folder to item 1 of target_folder as alias
set myname to the text returned of (display dialog "Enter Job Name" default answer "")
set myname2 to the text returned of (display dialog "Enter Job Number" default answer "")
set myname3 to the text returned of (display dialog "Enter Job date" default answer "day_month_year")
set myname4 to "RAW"
set myname5 to "Selects"
set myname6 to "Finals"
tell application "Finder"
make new folder with properties {name:myname & space & myname2 & space & myname3} at target_folder
make new folder with properties {name:myname2 & "_" & myname4}
make new folder with properties {name:myname2 & "_" & myname5}
make new folder with properties {name:myname2 & "_" & myname6}
end tell
end open
This works fine but I don’t know how to create the RAW, Selects and Finals so that they end up in the main folder {name:myname & space & myname2 & space & myname3} at target_folder
Any help would be greatly appreciated since the hours I’ve spent so far on this have probably erased any time saving benefits!?!
The ‘make new folder’ command will return a reference to the newly-created folder, so just use that as the target for the subsequent ‘make new folder’ commands:
set topFolder to make new folder with properties {name:myname & space & myname2 & space & myname3} at target_folder
make new folder at topFolder with properties {name:myname2 & "_" & myname4}
make new folder at topFolder with properties {name:myname2 & "_" & myname5}
make new folder at topFolder with properties {name:myname2 & "_" & myname6}
If you have a substantial number of objects to create, you can abbreviate your script somewhat by looping through a list, rather than by repeating similar lines of code. By placing such a list near the top of a script or handler, it can be amended more easily, too - should your requirements change at any time in the future:
on open target_folder
set nameList to {"RAW", "Selects", "Finals"}
set target_folder to item 1 of target_folder
set jobName to text returned of (display dialog "Enter Job Name" default answer "")
set jobNumber to text returned of (display dialog "Enter Job Number" default answer "")
set jobDate to text returned of (display dialog "Enter Job date" default answer "day_month_year")
tell application "Finder" to tell (make new folder at target_folder with properties {name:jobName & ¬
space & jobNumber & space & jobDate}) to repeat with currName in nameList
make new folder at it with properties {name:jobNumber & "_" & currName}
end repeat
end open