My first time automating a workflow in AccpleScript and I’m about 95% of the way there, and I think I’ve painted myself into a corner, as it were. The current workflow here involves moving vendor-delivered files into a new folder, renamed, relinked, and jpg previews of the main files are created. Normally this involves a lot of manual work and can be time consuming on large jobs. I’ve managed to simplify the manual stuff thus far (I’m not worried about automating the previews at this point), and I’m hoping for help on the following things:
A) (edit) Is there a way for me to make parts of the script skippable without terminating the entire script after it designates the main PDF (e.g., there are no “_ART” files, so move on to the next step)?
B) (edit) Is it possible to start at the projectFolder level when the user needs to select files? (DONE!)
C) (new) For each step where files are renamed (starting at the _ART rename step), how can I export the list of filenames changed, listing the before-and-after to a text file saved to the desktop, so that if files need to be relinked in InDesign or Illustrator, it will be easier for the user to reference the new file names?
I know this is a pretty verbose script, but I’m taking things a baby step at a time. Any help would be appreciated. Thanks!
—UPDATE: trimmed it out a bit so it’s a single Finder tell and updated the default folder location (thanks Marc!)
set text item delimiters to "."
set text item delimiters to "."
tell application "Finder"
--SETUP
--get Job code
display dialog "Enter Job Code:" default answer "JobCode"
set projCode to text returned of result
--designate project folder
set projectFolder to choose folder with prompt "Select project folder"
--ZIP FONTS & RENAME
set zipSuffix to "_TYPEFACES"
--pick font folder
set inputFolder to choose folder with prompt "Select font folder to be zipped"
tell current application
set qpp to quoted form of POSIX path of inputFolder
do shell script "cd $(dirname " & qpp & ")
zip -r \"$(basename " & projCode & zipSuffix & ").zip\" \"$(basename " & qpp & ")\""
end tell
--delete original files
delete inputFolder
--CREATE NEW PROJECT FOLDERS AND SORT FILES
make new folder at projectFolder with properties {name:"HIRES"}
--set path to move to HIRES folder
set hiFiles to (projectFolder as string) & "HIRES"
-- move all files to HIRES
set targetFiles to get every item of (entire contents of projectFolder) whose kind ≠"Folder"
--more files into HIRES
move targetFiles to hiFiles
--remove extraneous folders
delete (every folder of projectFolder whose name is not "HIRES")
--create previews folder
make new folder at projectFolder with properties {name:"PREVIEWS"}
--DESIGNATE MAIN MECHANICAL
--pick the file
set mainMech to (choose file default location projectFolder with prompt "Select primary mechanical file:")
--get the filename to save the extension
set mainFNCount to text items of (get name of mainMech)
--pull original filename extension
if number of mainFNCount is 1 then
set mainExt to ""
else
set mainExt to "." & item -1 of mainFNCount
end if
--rename file
set the name of mainMech to projCode & mainExt as string
--DESIGNATE MAIN PDF
--pick the file
set mainPDF to (choose file default location projectFolder with prompt "Select primary PDF file:")
--get the filename to save the extension
set mainFNCount to text items of (get name of mainPDF)
--pull original filename extension
if number of mainFNCount is 1 then
set mainExt to ""
else
set mainExt to "." & item -1 of mainFNCount
end if
--rename file
set the name of mainPDF to projCode & "_PDF01" & mainExt as string
--RENAME ALL _ART FILES IN SEQUENCE
set all_files to every item of (choose file default location projectFolder with prompt "Select all _ART files:" with multiple selections allowed) as list
--add in the support filename suffix
set artSuffix to "_ART"
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
--the 'index' number is required for the sequential renaming of files
repeat with index from 1 to the count of all_files
--using our index, we select the appropriate file from our list
set this_file to item index of all_files
set file_name_count to text items of (get name of this_file)
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
if index is less than 10 then
set index_prefix to "0"
else
set index_prefix to ""
end if
--lets check if the current file from our list (based on index-number) has even any file-extension
if number of file_name_count is 1 then
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
set file_extension to ""
else
--re-add the original file-extension after changing the name of the file
set file_extension to "." & item -1 of file_name_count
end if
--rename file, add the sequential number from 'index' and add the file-extension to it
set the name of this_file to projCode & artSuffix & index_prefix & index & file_extension as string
end repeat
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
--RENAME ALL _BIT FILES IN SEQUENCE
set all_files to every item of (choose file default location projectFolder with prompt "Select all _BIT files:" with multiple selections allowed) as list
--add in the support filename suffix
set bitSuffix to "_BIT"
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
--the 'index' number is required for the sequential renaming of files
repeat with index from 1 to the count of all_files
--using our index, we select the appropriate file from our list
set this_file to item index of all_files
set file_name_count to text items of (get name of this_file)
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
if index is less than 10 then
set index_prefix to "0"
else
set index_prefix to ""
end if
--lets check if the current file from our list (based on index-number) has even any file-extension
if number of file_name_count is 1 then
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
set file_extension to ""
else
--re-add the original file-extension after changing the name of the file
set file_extension to "." & item -1 of file_name_count
end if
--rename file, add the sequential number from 'index' and add the file-extension to it
set the name of this_file to projCode & bitSuffix & index_prefix & index & file_extension as string
end repeat
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
--RENAME ALL _LYRD FILES IN SEQUENCE
set all_files to every item of (choose file default location projectFolder with prompt "Select all _LYRD files:" with multiple selections allowed) as list
--add in the support filename suffix
set lyrdSuffix to "_LYRD"
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
--the 'index' number is required for the sequential renaming of files
repeat with index from 1 to the count of all_files
--using our index, we select the appropriate file from our list
set this_file to item index of all_files
set file_name_count to text items of (get name of this_file)
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
if index is less than 10 then
set index_prefix to "0"
else
set index_prefix to ""
end if
--lets check if the current file from our list (based on index-number) has even any file-extension
if number of file_name_count is 1 then
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
set file_extension to ""
else
--re-add the original file-extension after changing the name of the file
set file_extension to "." & item -1 of file_name_count
end if
--rename file, add the sequential number from 'index' and add the file-extension to it
set the name of this_file to projCode & lyrdSuffix & index_prefix & index & file_extension as string
end repeat
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
--RENAME ALL _IL FILES IN SEQUENCE
set all_files to every item of (choose file default location projectFolder with prompt "Select all _IL files:" with multiple selections allowed) as list
--add in the support filename suffix
set ilSuffix to "_IL"
--start looping through all selected files. 'index' is our counter that we initially set to 1 and then count up with every file.
--the 'index' number is required for the sequential renaming of files
repeat with index from 1 to the count of all_files
--using our index, we select the appropriate file from our list
set this_file to item index of all_files
set file_name_count to text items of (get name of this_file)
--if the index number is lower than 10, we will add a preceding "0" for a proper filename sorting later
if index is less than 10 then
set index_prefix to "0"
else
set index_prefix to ""
end if
--lets check if the current file from our list (based on index-number) has even any file-extension
if number of file_name_count is 1 then
--file_name-count = 1 means, we extracted only 1 text-string from the full file name. So there is no file-extension present.
set file_extension to ""
else
--re-add the original file-extension after changing the name of the file
set file_extension to "." & item -1 of file_name_count
end if
--rename file, add the sequential number from 'index' and add the file-extension to it
set the name of this_file to projCode & ilSuffix & index_prefix & index & file_extension as string
end repeat
display notification "File Rename Complete " & index & " files with '" & projCode & "' for you."
end tell