Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lifequest

macrumors regular
Original poster
Feb 9, 2010
111
0
I have a simple script that allows me to rename files from a CSV.
Column 1 files to renamed into column 2.
It was working a few months ago on 10.11.
I'm running 10.12.1 at the moment. Mentioning this as I can't think of any other changes.

Notes: all image files in /rename
csv file is also in /rename

image 1. flow
image 2. error

Script that I frankensteined together from searching various threads;

cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
NewImageName=$( echo "$NewImageName" | tr -d '\r' )
if [ -e "$OldImageName" ] ; then
mv "$OldImageName" "$NewImageName"
else
echo "$OldImageName" >> ~/Desktop/Errors.txt
fi
done <"$2"error



Thank you

hNwU3du.jpg
WCTW7TH.jpg
 
any ideas would greatly help. I don't know how the path can be wrong as it's selected from the ask for finder items menu
 
1. Launch Terminal.app.

2. Copy the following line to the clipboard, then paste it into a Terminal window:
Code:
ls -l ~/Desktop/rename

3. Click-and-drag to select the entire output in the Terminal window, then copy to clipboard and paste it into a post here.
Please use CODE tags around the posted output.


The script you posted has this as its last line:
Code:
done <"$2"error
I don't know why you've concatenated the word "error" to the filename, but that's what it's doing.

You can see the result in the penultimate line of the error alert, where it shows the name of the file that the 'while' command fails on. Note the filename is "rename.csverror". So the shell script is doing exactly what you asked for, although you may not have realized you were asking for that.


When you "frankenstein" a program together, it's always a good idea to provide the original sources in your question, by posting their URLs. This lets us see what the original code was, and what its intent was.

Errors come in many forms: errors of intent (i.e. misapplication of code to a situation), design or implementation errors in the original code, or errors introduced in your adaptation, or even simple typos. Seeing the whole pathway from origin to result provides important information.


EDIT
I got around to looking at your past posts, and you used a similar Automator and shell script process here:
https://forums.macrumors.com/threads/automater-workflow-rename-from-csv-small-problem.2030795/

That shell script doesn't have the word "error" at the end of it, so my guess is that you've somehow typed or pasted it into the Automator action's script, or it otherwise got there accidentally. However it got there, it shouldn't be there.

Basically, you need to make the last line of the shell script in this thread look exactly like the last line of the shell script in your earlier thread.
 
Last edited:
Thank you very much for your assistance.
I don't know how error was added, but I must have done it in my stupor. I have since deleted it and tried it again, a new error came up which I have attached. I then ran terminal as per instructed and this is the output.

I can't remember where i assembled this small bit of code as it was so long ago.

Code:
Last login: Wed Oct 25 22:45:05 on ttys002
Nates-MBP-2:~ Nate$ ls -l ~/Desktop/rename
total 3608
-rw-r--r--@   1 Nate  staff  33699 20 Oct 11:26 1104946.jpg
-rw-r--r--@   1 Nate  staff  39630 20 Oct 11:26 1104947.jpg
-rw-r--r--@   1 Nate  staff  46505 20 Oct 11:29 1109883.jpg
-rw-r--r--@   1 Nate  staff  44110 20 Oct 11:29 1109884.jpg
-rw-r--r--@   1 Nate  staff  43564 20 Oct 11:29 1109885.jpg
-rw-r--r--@   1 Nate  staff  41803 20 Oct 11:30 1109886.jpg
-rw-r--r--@   1 Nate  staff  37524 20 Oct 11:30 1109887.jpg
-rw-r--r--@   1 Nate  staff  41175 20 Oct 11:28 1109888.jpg
-rw-r--r--@   1 Nate  staff  41937 20 Oct 11:30 1109889.jpg
-rw-r--r--@   1 Nate  staff  40977 20 Oct 11:30 1109890.jpg
-rw-r--r--@   1 Nate  staff  38549 20 Oct 11:30 1109891.jpg
-rw-r--r--@   1 Nate  staff  39894 20 Oct 11:29 1109892.jpg
-rw-r--r--@   1 Nate  staff  42136 20 Oct 11:29 1109893.jpg
-rw-r--r--@   1 Nate  staff  46551 20 Oct 11:28 1109894.jpg
-rw-r--r--@   1 Nate  staff  43630 20 Oct 11:28 1109895.jpg
-rw-r--r--@   1 Nate  staff  44887 20 Oct 11:30 1109896.jpg
-rw-r--r--@   1 Nate  staff  39730 20 Oct 11:30 1109897.jpg
-rw-r--r--@   1 Nate  staff  46155 20 Oct 11:28 1109898.jpg
-rw-r--r--@   1 Nate  staff  38605 20 Oct 11:27 1109899.jpg
-rw-r--r--@   1 Nate  staff  36322 20 Oct 11:30 1109900.jpg
-rw-r--r--@   1 Nate  staff  43651 20 Oct 11:25 1109901.jpg
-rw-r--r--@   1 Nate  staff  37292 20 Oct 11:26 1109902.jpg
-rw-r--r--@   1 Nate  staff  39843 20 Oct 11:26 1109903.jpg
-rw-r--r--@   1 Nate  staff  34531 20 Oct 11:26 1109904.jpg
-rw-r--r--@   1 Nate  staff  36980 20 Oct 11:27 1109905.jpg
-rw-r--r--@   1 Nate  staff  37647 20 Oct 11:28 1109906.jpg
-rw-r--r--@   1 Nate  staff  40396 20 Oct 11:27 1109907.jpg
-rw-r--r--@   1 Nate  staff  35439 20 Oct 11:27 1109908.jpg
-rw-r--r--@   1 Nate  staff  30875 20 Oct 11:27 1109909.jpg
-rw-r--r--@   1 Nate  staff  34004 20 Oct 11:26 1109910.jpg
-rw-r--r--@   1 Nate  staff  25489 20 Oct 11:31 1109911.jpg
-rw-r--r--@   1 Nate  staff  35816 20 Oct 11:27 1109912.jpg
-rw-r--r--@   1 Nate  staff  34686 20 Oct 11:27 1109913.jpg
-rw-r--r--@   1 Nate  staff  34792 20 Oct 11:29 1109914.jpg
-rw-r--r--@   1 Nate  staff  35965 20 Oct 11:29 1109915.jpg
-rw-r--r--@   1 Nate  staff  37118 20 Oct 11:28 1109916.jpg
-rw-r--r--@   1 Nate  staff  39031 20 Oct 11:27 1109917.jpg
-rw-r--r--@   1 Nate  staff  37496 20 Oct 11:28 1109918.jpg
-rw-r--r--@   1 Nate  staff  33159 20 Oct 11:30 1109919.jpg
-rw-r--r--@   1 Nate  staff  34446 20 Oct 11:26 1109920.jpg
-rw-r--r--@   1 Nate  staff  35042 20 Oct 11:27 1109921.jpg
-rw-r--r--@   1 Nate  staff  33557 20 Oct 11:26 1109922.jpg
-rw-r--r--@   1 Nate  staff  42366 20 Oct 11:28 1109923.jpg
-rw-r--r--@   1 Nate  staff  43832 20 Oct 11:29 1109924.jpg
-rw-r--r--@   1 Nate  staff  40085 20 Oct 11:28 1109925.jpg
drwxr-xr-x  114 Nate  staff   3876 26 Jan  2016 EXHP
drwxr-xr-x  151 Nate  staff   5134 11 Sep  2016 JPEG
drwxr-xr-x@   3 Nate  staff    102 26 Oct 13:06 Rename Utility.workflow
drwxr-xr-x  114 Nate  staff   3876 26 Jan  2016 Reverse
drwxr-xr-x  311 Nate  staff  10574  3 Feb  2017 SM1
drwxr-xr-x    8 Nate  staff    272 24 Oct 20:51 editing
drwx------    4 Nate  staff    136 27 Jan  2016 exhiddenlegends
drwx------    4 Nate  staff    136 31 Jan  2016 expk
drwx------    4 Nate  staff    136  8 Feb  2016 extmvsta
drwxr-xr-x@   3 Nate  staff    102 20 Oct 12:06 rename location predetermined.workflow
-rw-r--r--@   1 Nate  staff   1118 20 Oct 12:04 rename.csv
drwxr-xr-x   92 Nate  staff   3128 18 Sep  2016 variable
Nates-MBP-2:~ Nate$

xpg0wxY.jpg
 
Thank you very much for your assistance.
I don't know how error was added, but I must have done it in my stupor. I have since deleted it and tried it again, a new error came up which I have attached. I then ran terminal as per instructed and this is the output.

I can't remember where i assembled this small bit of code as it was so long ago.

Code:
Last login: Wed Oct 25 22:45:05 on ttys002
Nates-MBP-2:~ Nate$ ls -l ~/Desktop/rename
total 3608
-rw-r--r--@   1 Nate  staff  33699 20 Oct 11:26 1104946.jpg
-rw-r--r--@   1 Nate  staff  39630 20 Oct 11:26 1104947.jpg
-rw-r--r--@   1 Nate  staff  46505 20 Oct 11:29 1109883.jpg
-rw-r--r--@   1 Nate  staff  44110 20 Oct 11:29 1109884.jpg
-rw-r--r--@   1 Nate  staff  43564 20 Oct 11:29 1109885.jpg
-rw-r--r--@   1 Nate  staff  41803 20 Oct 11:30 1109886.jpg
-rw-r--r--@   1 Nate  staff  37524 20 Oct 11:30 1109887.jpg
-rw-r--r--@   1 Nate  staff  41175 20 Oct 11:28 1109888.jpg
-rw-r--r--@   1 Nate  staff  41937 20 Oct 11:30 1109889.jpg
-rw-r--r--@   1 Nate  staff  40977 20 Oct 11:30 1109890.jpg
-rw-r--r--@   1 Nate  staff  38549 20 Oct 11:30 1109891.jpg
-rw-r--r--@   1 Nate  staff  39894 20 Oct 11:29 1109892.jpg
-rw-r--r--@   1 Nate  staff  42136 20 Oct 11:29 1109893.jpg
-rw-r--r--@   1 Nate  staff  46551 20 Oct 11:28 1109894.jpg
-rw-r--r--@   1 Nate  staff  43630 20 Oct 11:28 1109895.jpg
-rw-r--r--@   1 Nate  staff  44887 20 Oct 11:30 1109896.jpg
-rw-r--r--@   1 Nate  staff  39730 20 Oct 11:30 1109897.jpg
-rw-r--r--@   1 Nate  staff  46155 20 Oct 11:28 1109898.jpg
-rw-r--r--@   1 Nate  staff  38605 20 Oct 11:27 1109899.jpg
-rw-r--r--@   1 Nate  staff  36322 20 Oct 11:30 1109900.jpg
-rw-r--r--@   1 Nate  staff  43651 20 Oct 11:25 1109901.jpg
-rw-r--r--@   1 Nate  staff  37292 20 Oct 11:26 1109902.jpg
-rw-r--r--@   1 Nate  staff  39843 20 Oct 11:26 1109903.jpg
-rw-r--r--@   1 Nate  staff  34531 20 Oct 11:26 1109904.jpg
-rw-r--r--@   1 Nate  staff  36980 20 Oct 11:27 1109905.jpg
-rw-r--r--@   1 Nate  staff  37647 20 Oct 11:28 1109906.jpg
-rw-r--r--@   1 Nate  staff  40396 20 Oct 11:27 1109907.jpg
-rw-r--r--@   1 Nate  staff  35439 20 Oct 11:27 1109908.jpg
-rw-r--r--@   1 Nate  staff  30875 20 Oct 11:27 1109909.jpg
-rw-r--r--@   1 Nate  staff  34004 20 Oct 11:26 1109910.jpg
-rw-r--r--@   1 Nate  staff  25489 20 Oct 11:31 1109911.jpg
-rw-r--r--@   1 Nate  staff  35816 20 Oct 11:27 1109912.jpg
-rw-r--r--@   1 Nate  staff  34686 20 Oct 11:27 1109913.jpg
-rw-r--r--@   1 Nate  staff  34792 20 Oct 11:29 1109914.jpg
-rw-r--r--@   1 Nate  staff  35965 20 Oct 11:29 1109915.jpg
-rw-r--r--@   1 Nate  staff  37118 20 Oct 11:28 1109916.jpg
-rw-r--r--@   1 Nate  staff  39031 20 Oct 11:27 1109917.jpg
-rw-r--r--@   1 Nate  staff  37496 20 Oct 11:28 1109918.jpg
-rw-r--r--@   1 Nate  staff  33159 20 Oct 11:30 1109919.jpg
-rw-r--r--@   1 Nate  staff  34446 20 Oct 11:26 1109920.jpg
-rw-r--r--@   1 Nate  staff  35042 20 Oct 11:27 1109921.jpg
-rw-r--r--@   1 Nate  staff  33557 20 Oct 11:26 1109922.jpg
-rw-r--r--@   1 Nate  staff  42366 20 Oct 11:28 1109923.jpg
-rw-r--r--@   1 Nate  staff  43832 20 Oct 11:29 1109924.jpg
-rw-r--r--@   1 Nate  staff  40085 20 Oct 11:28 1109925.jpg
drwxr-xr-x  114 Nate  staff   3876 26 Jan  2016 EXHP
drwxr-xr-x  151 Nate  staff   5134 11 Sep  2016 JPEG
drwxr-xr-x@   3 Nate  staff    102 26 Oct 13:06 Rename Utility.workflow
drwxr-xr-x  114 Nate  staff   3876 26 Jan  2016 Reverse
drwxr-xr-x  311 Nate  staff  10574  3 Feb  2017 SM1
drwxr-xr-x    8 Nate  staff    272 24 Oct 20:51 editing
drwx------    4 Nate  staff    136 27 Jan  2016 exhiddenlegends
drwx------    4 Nate  staff    136 31 Jan  2016 expk
drwx------    4 Nate  staff    136  8 Feb  2016 extmvsta
drwxr-xr-x@   3 Nate  staff    102 20 Oct 12:06 rename location predetermined.workflow
-rw-r--r--@   1 Nate  staff   1118 20 Oct 12:04 rename.csv
drwxr-xr-x   92 Nate  staff   3128 18 Sep  2016 variable
Nates-MBP-2:~ Nate$
The listing shows a "rename.csv" file is present in the expected place. This confirms expectations, but it's not yet a complete answer nor a solution.


The latest error alert seems to be saying that the 'while ... done' block isn't having its input redirected to a real file, and that there's a problem with the 'then' (or a misplaced 'then'). The odd thing about the "No such file" is that I can't discern what file or directory name it's complaining about. It should normally list the problematic pathname This suggests either errant characters in the shell script, or something else is syntactically incorrect.

Please post the complete contents of the Run Shell Script action, using CODE tags around the script.


I also suggest starting from a very simple known-good script. The purpose of this is to ensure there aren't any unexpected characters or other junk in the shell script.

Please replace the entire shell script with this:
Code:
echo "$1"
echo "$2"

There are a couple ways to do this without losing the script you have now. A simple one is to copy and paste the current script into a new file in Text Editor, and save it as plain text. This gives you something you can copy and paste back later. Or you can duplicate the original workflow, and edit the duplicate. Do one of those BEFORE replacing the script with the two echo lines.

The output from the script will just be two pathnames. You should be able to see this in the output of the entire workflow. Furthermore, there should be no error alerts. If there are any error alerts, post them.

You look at the workflow output by clicking the "Results" button at the lower left of the Run Shell Script action. You may have to click another icon to get it to show a list of items in pathname form. Post that list.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.