Applescript - creat a folder, subfolders and populate with sample image
Please help me achieve this, probably, simple goal.
I've only done a very small amount of applescripting before and have always butchered other script resources found online but am having trouble working out how to get this done.
I would like to use applescript to automate the creation of a simple folder structure of newFolder and newSubFolders in a destination that the user can choose and the number of subfolders (subCount) chosen using the prompt:
set subCount to text returned of (display dialog "How many subfolders?" default answer 85)
The newFolder will always be in a format of date in reverse eg 160202 for 2nd February 2016.
The sub folder names to end with 3 numerical characters, so leading 0s for any folder number less that 100:
160202_001, 160202_002, 160202_003 etc etc.
Along with all of the above need the user will choose an image file and have it duplicated, or should that be copied, to all of the subFolders created by this script.
All I have managed so far is to create a script that creates the folder structure with subfolders but cannot work out how to make the names of the folders end with the 3 numerical characters, or work out how to copy/duplicate a file to every subfolder created by the script.
Here is my starting point:
set JobName to text returned of (display dialog "Please enter Date Reference:" default answer "160411")
set loc to choose folderwith prompt "Choose Parent Folder Location:"
tell application "Finder"
set targetFolder to makenewfolderatlocwith properties {name:JobName}
end tell
repeat
set subCount to text returned of (display dialog "How many subfolders?" default answer 85)
try
if subCount ≠ "" then
subCount as integer
exit repeat
end if
end try
end repeat
repeat with i from 1 to subCount
display dialog "my variable: " & i
tell application "Finder" to makenewfolderattargetFolderwith properties {name:JobName & "_" & i}
end repeat
set filetoCopy to choose filewith prompt "Choose the image file to copy."
display dialog "my variable: " & filetoCopy
It doesn't really matter to me which order the script has to happen in, i.e. the the image file to be copied can be chosen first before the creation of the all subfolders etc.... as long as the end result is the same structure.
I had a look into adding leading 0s to a folder name but didn't really understand how i could do this within the repeat that exists in my script.
Any help very much appreciated.
Mike