AppleScript - creat a folder, subfolders and fill it with the sample image

Please help me to achieve this goal, no doubt, simple goal.

I did only a very small amount of applescripting before and always slaughtered other scripts of resources available online but am having hard to identify ways to achieve this.

I would like to use applescript to automate the creation of a simple folder NewFolder and newSubFolders structure in a destination that the user can choose and the number of subfolders (subCount), selected using the command prompt:


subCount value to text returned of (display dialog "how subfolders?" by default of answer 85)

The NewFolder will always be in a format of date backwards for example 160202 for 2 February 2016.

The sub folder names end with 3 numeric characters, leading 0s to whole number less than 100:

160202_001, 160202_002, 160202_003 etc etc.

With all these responses need the user to select an image file and duplicated it or should that be copied to all of the subfolders created by this script.

All I got so far is to create a script that creates the folder with subfolders structure, but does not work how do the names of the end of records with 3 numeric characters or find out how copy/duplicate a file for each subfolder created by the script.

Here's my starting point:

the value JobName to text returned of (display dialog "Please enter Date reference:" default of '160411' response)

loc to choose a folder with guest "choose the Parent folder location:

say application 'Finder '.

targetFolder value to create a new folder in loc with properties {name: JobName}

end say

Repeat

subCount value to text returned of (display dialog "how subfolders?" by default of answer 85)

Try

If subCount ≠ "" then

whole subCount

output Repeat

end if

end try

end Repeat

Repeat with I have from 1 to subCount

display the dialog box "my variable:"& I ".

say application "Finder" to create a new folder to targetFolder with properties {name: JobName & "_" & I}

end Repeat

filetoCopy to Choose file with prompt "choose the image file to be copied."

display the dialog box "my variable:" & filetoCopy ".

It does not really matter I order in which the script should occur, i.e. the image file to be copied can be selected first before the creation of the all the subfolders etc... as long as the end result is the same structure.

I had a look by adding leading 0s to a name of folder but don't really understand how I could do within the repetition that exists in my script.

Any help much appreciated.

Mike

Although this still needs a lot of storage (including the addition of error checking) I managed to get working folders creating and copying a file to the set of folders.

I'd appreciate it again any help in renaming with 000 leader after the _in, folder names.

Here's where I'm up to:

the value JobName to text returned of (display dialog "Please enter Date reference:" default of '160411' response)

loc to choose a folder with guest "choose the Parent folder location:

say application 'Finder '.

targetFolder value to create a new folder in loc with properties {name: JobName}

end say

Repeat

subCount value to text returned of (display dialog "how subfolders?" by default of answer 85)

Try

If subCount ≠ "" then

whole subCount

output Repeat

end if

end try

end Repeat

Repeat with I have from 1 to subCount

say application "Finder" to create a new folder to targetFolder with properties {name: JobName & "_" & I}

end Repeat

say application 'Finder '.

_destination to choose a folder with guest from "choose the main folder created above:

filetoCopy to Choose file with guest "choose image file copy:

display the dialog box "my variable:" & filetoCopy ".

the value _listOfDest to (each of _destination folder ) as alias list

Repeat with CurrentNumber from 1 to (count _listOfDest)

duplicate filetoCopy file to the file (article of _listOfDest CurrentNumber)

end Repeat

end say



Tags: Mac OS & System Software

Similar Questions

Maybe you are looking for