From your Dock, click LaunchPad and look for the Other folder icon, containing Automator.
- Launch Automator, and select New Document, Application, and click Choose.
- Drag and drop the following into the larger right-hand workflow window:
- Library : Files & Folders : Ask for Finder Items action
- Start at: Desktop
- Type: Folders (do not select Allow Multiple Selection
- Library : Utilities : Run Shell Script action
- Shell: /bin/zsh
- Pass input: as arguments
- Replace the boiler plate for loop with the code from the Zsh code content below.
- Library : Utilities : Run AppleScript action
- Replace default AppleScript content with the code from the AppleScript code below
- Save the Automator application to your Desktop with an arbitrary name. Double-click to launch it.
- Quit Automator.
All the Automator application requires of you is to select the folder containing the files to rename and the CSV that you have located there. It will process the CSV row by row, and rename the files per your CSV entries. When it has finished with the CSV, it will determine whether an error occurred or not and pass the renamed file count appended to either true or false. This is passed on to the AppleScript action, where if successful, a dialog will appear informing you that processing is complete and a file count.
![](https://discussions.apple.com/content/attachment/d081187f-385c-4b25-9511-2dc404035b65)
Zsh code
#!/bin/zsh
#
: <<'COMMENT'
Process two column CSV by line, and move (rename) old filename to new filename
in specified directory location. Report files that do not exist.
COMMENT
# zsh shell arrays are 1 based
OLDFILE=1
NEWFILE=2
# drop into selected folder chosen from Ask for Finder Items action
cd "${1}"
CSVFILE="titles.csv"
# a regular array to hold parts of CSV row
typeset -a csv=()
let cnt=0
while read -r line
do
# split csv line on commas into array elements
# remove double-quotes from each column entry — if they exist
csv=("${(@s/,/)line}")
old_file="${csv[$OLDFILE]:gs/\"//}"
new_file="${csv[$NEWFILE]:gs/\"//}"
# if old filename exists then rename it
if [ -e $old_file ]; then
mv "${old_file}" "${new_file}"
(( cnt++ ))
else
echo "${old_file}" >> ~/Desktop/Errors.txt
(( cnt-- ))
fi
# Only if created on Windows, remove carriage returns from line endings
done < <(perl -lne '$_ =~ s/\015?//g && print;' "${CSVFILE:a:l}")
# if return code from above is 0 then processing was successful and we return
# true with the renamed file count
[[ $? -eq 0 ]] && echo "true $cnt" || echo "false $cnt"
AppleScript code
on run {input, parameters}
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, space}
set temp to text items of (input as text)
set AppleScript's text item delimiters to TID
set status to (item 1 of temp) as boolean
set cnt to (rest of temp) as text
if status then
display dialog "Processing complete with " & cnt & " files renamed." with title "Processing Status"
else
display dialog "There was an unknown problem" with title "Processing Status"
end if
return input
end run