-
All replies
-
Helpful answers
-
Jan 30, 2014 6:29 PM in response to userremovedby Tony T1,★HelpfulShould be simple with this bash script.
Change ~/Documents to the Folder where the files reside (assumes that the csv file and the jpg files are in the same Folder):
#!/bin/bash
cd ~/Documents
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
mv "$OldImageName" "$NewImageName"
done <"TheFile.csv"
-
Jan 30, 2014 6:43 PM in response to userremovedby twtwtw,★HelpfulIn applescript it goes something like this:
(*
this all assuming the CSV file is a plain text file with a comma delimiting
the old and new filenames on a given line. If you have another structure
you need to give specifics so this can be modified
*)
set theCSVData to paragraphs of (read "/path/to/theCSVFile.csv")
set {oldTID, my text item delimiters} to {my text item delimiters, ","}
repeat with thisLine in theCSVData
set {oldFileName, newFileName} to text items of thisLine
tell application "System Events"
set name of file oldFileName of folder "path/to/folder of images" to newFileName
end tell
end repeat
set my text item delimiters to oldTID
Note that I've made a lot of assumptions about your csv file, any or all of which may be wrong. please clarify as needed.
-
Jan 30, 2014 6:51 PM in response to userremovedby Tony T1,You can also make this into and Automator Workflow or App.
Add this shell script:
cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
mv "$OldImageName" "$NewImageName"
done <"$2"
as part of this Automator Workflow:
Edit: twtwtw posted an Applescript example (which is what you're looking for) while I was posting this Automator example. You now have 3 ways to tackle your problem
-
Dec 27, 2015 4:28 PM in response to Tony T1by userremoved,Hello, thanks for the quick reply. I have tried using the script but can't seem to get it working. When I click Run on the AppleScript Editor I get a message stating:
Syntax Error
Expected end of line, etc. but found “while”.
Below is what I have changed. I put the CSV file in the same folder as the images
#!/bin/bash
cd /Users/aaron/Desktop/Images
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
mv "$OldImageName" "$NewImageName"
done <"/Users/aaron/Desktop/Images/CSVFile.csv"
-
Jan 30, 2014 6:54 PM in response to userremovedby Tony T1,I posted a bash script, not an Applescript.
You would need to run this from Terminal.
Better to use twtwtw's Applescript example below if you're not familiar with bash scripts and Terminal
-
Dec 27, 2015 4:28 PM in response to Tony T1by userremoved,Hello twtwtw,
I have tried your script and I get the following error message:
error "System Events got an error: Can’t set file \"Old Image Name\" of folder \"/Users/aaron/Desktop/Images\" to \"New Image Name\"." number -10006 from file "Old Image Name" of folder "/Users/aaronkitney/Desktop/Images"
How shall I export the CSVFile from Numbers? I currently export as Unicode UTF-8. Shall I put the CSVFile on my desktop or inside the images folder?
Thanks for your help as well Tony,
-
Jan 30, 2014 7:57 PM in response to userremovedby twtwtw,Sorry, I didn't realize the headers were written directly into the CSV file. You'll want to skip the first line. Or maybe better, catch and ignore file-doesn't-exist errors like so:
tell application "System Events"
try
set name of file oldFileName of folder "path/to/folder of images" to newFileName
end try
end tell
-
Dec 27, 2015 4:28 PM in response to userremovedby userremoved,Hello Tony,
I managed to get your idea your Automator version working, really happy. Thanks.
I did have another Automator/Script issue that , istead of processing images I would like to rename the file image file in the Numbers doc. I need to put a _1 after about 600 images
As I am uploading two images per product item onto the website, I can't have them named the same because they will overwrite each other on the FTP. I'm not sure if it's easier to add _1 to every row name in Numbers, or save out the images (using the previous script provided) into a differen't folder (so it doesn't overide on my desktop) then add _1 to the each image. Either way I'm not sure how to write a script to accomadate this.
If this is confusing I make a few screen shots to help explain
I can't express how grateful I am already, I spent most of today testing different plugins to no avail
-
Jan 31, 2014 4:40 AM in response to userremovedby Tony T1,kittersa wrote:
I managed to get your idea your Automator version working, really happy. Thanks.
Great
I'm not sure if it's easier to add _1 to every row name in Numbers
If you can add it to a new column, then you could just use a formula:
....or save out the images (using the previous script provided) into a differen't folder (so it doesn't overide on my desktop) then add _1 to the each image.
To do this, add one line in the script to first Copy and rename (cp) before the rename (mv)
cp "$OldImageName" ~/Documents/"$NewImageName"_1
so the script (to add to Automator) now looks like:
(this will copy and rename first to the Documents Folder)
cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
cp "$OldImageName" ~/Documents/"$NewImageName"_1
mv "$OldImageName" "$NewImageName"
done <"$2"
-
Jan 31, 2014 5:03 AM in response to Tony T1by Tony T1,Oh, if you want the files with _1 in the same folder, just delete ~/Documents/ and use:
cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
cp "$OldImageName" "$NewImageName"_1
mv "$OldImageName" "$NewImageName"
done <"$2"
-
Dec 27, 2015 4:28 PM in response to Tony T1by userremoved,Thanks.
Going back to my original issue. After I finished my first batch of images I renamed that folder to 'Featured Images' and created a new folder called 'Images'. I tried to batch rename another CSV file with my Supporting website Images, but I encounter an error again. I cant figure out what I'm doing wrong. I'm essentially just trying to copy the script as before
I've attached an image - the error can be seen at the bottom of Automator

-
-
Dec 27, 2015 4:28 PM in response to Tony T1by userremoved,Dreamy. Glad you spot that.
Thanks again
-




