Search code examples
applescriptdirectoryfinder

Create Folders Applescript


I have an Applescript that I use to create job folders. The Applescript asks for the project name and the location where the folder will be stored. After inputting the job name and folder location, the script creates the main folder and four subfolders.

Now I would like the script to create numbered subfolders within one of the current subfolders, with a prompt that asks the user how many folders to create. Is that possible?

tell application "Finder"
    set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
    set loc to choose folder "Choose Parent Folder Location"
    set newfoldername to JobName
    set newfo to make new folder at loc with properties {name:newfoldername}
    make new folder at newfo with properties {name:"Job Materials"}
    make new folder at newfo with properties {name:"Previews"}
    make new folder at newfo with properties {name:"PSDs"}
    make new folder at newfo with properties {name:"VX"}
end tell

Solution

  • set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
    set loc to choose folder "Choose Parent Folder Location"
    
    tell application "Finder"
        set newfo to make new folder at loc with properties {name:JobName}
        make new folder at newfo with properties {name:"Job Materials"}
        make new folder at newfo with properties {name:"Previews"}
        set targetFolder to make new folder at newfo with properties {name:"PSDs"}
        make new folder at newfo with properties {name:"VX"}
    end tell
    
    repeat
        set subCount to text returned of (display dialog "How many subfolders?" default answer 3)
        try
            if subCount ≠ "" then
                subCount as integer
                exit repeat
            end if
        end try
    end repeat
    
    repeat with i from 1 to subCount
        tell application "Finder" to make new folder at targetFolder with properties {name:"Subfolder " & i}
    end repeat