I have pieced together two scripts that I have that will generate a set of folders in a correct structure based on a user inputting a number
Two issues:
-
I set it up to replace any foreign characters that the user may input in the name with “_”
This works fine, but one of the folders generated are “12345_Transmissions”, and I cannot get the script to create two folders within this one called “In” & “Out” -
I haven’t been working with applescript in a while, and I am trying to refresh myself, so I realize that this script may be more complex than needed, Is there an easier way to write what I need
Basically I want a user to give me a job number based on this structure:“XXXX_XXXX_12345”, this number is used to build a file structure like this:
“XXXX_XXXX_12345”-main folder
“12345_12345_EPS_TIF”, “12345_ILL_EPS”, “12345_Old_QXD”, “12345_PSD”, “12345_Resources”, “12345_Transmissions” as sub-folders inside main folder
Inside of “12345_Transmissions” I need two folders: “In” & “Out”
Here’s what I have thus far:
on run
set destination_ to choose folder with prompt "Choose a destination for the job folder."
set dd to (display dialog "Enter Your FCB Job Number." default answer "XXXX_XXXX_12345")
set prefix_ to text -5 thru end of text returned of dd
set subfolder_names to {"Old_QXD", "ILL_EPS", "PSD", "Transmissions", "Resources", "EPS_TIF"}
set transmission_names to {"In", "Out"}
tell application "Finder"
try
--make FCB Job Number Folder--
set nf to make new folder at destination_ with properties {name:text returned of dd}
--make sub-folders for job--
repeat with name_ in subfolder_names
set sub_ to (make new folder at nf with properties {name:prefix_ & "_" & name_})
end repeat
set elem to nf as string
set fileItem to alias elem
set strName to name of fileItem
set replace_strings to ¬
{" ", " ", "-", "_", "__", "~", "`", ":", ";", "!", "@", "™", "'", "®", "#", "$", "?", "<", ">", "%", "^", "&", ¬
"*", "(", ")", "=", "+", "{", "}", "[", "]", "|", "\", "/", "'", ",", """}
repeat with this_replace_string in replace_strings
set strName to my FixName(strName, (contents of this_replace_string))
end repeat
set name of nf to strName
--making In & Out folder in Transmissions--
get name of sub_
if name of sub_ is (prefix_ & "_Transmissions") then
repeat with item_ in transmission_names
make new folder at sub_ with properties {name:item_}
end repeat
end if
on error e
end try
end tell
end run
on FixName(currentName, fixString)
set AppleScript’s text item delimiters to fixString
set listName to every text item of currentName
set AppleScript’s text item delimiters to “_”
return (listName as string)
end FixName