Mac Automater - File Rename Based of CSV

Hi,


I am trying to use Automator to rename jpgs on my NAS based of a CSV.


Typically the images are name 001.jpg,002.jpg,003jpg and need might need renaming orange.jpg,blue.jpg,yellow.jpg.


I have setup a csv, first column is the old name and second column is the new name.


My process so far is the following, however I keep hitting the same error message.



Error message:



Thank you for your help :)

Posted on Oct 13, 2023 9:00 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 13, 2023 11:07 AM

You second Ask for Finder Items should be Type: Folder, not Files.


This Automator application will process the CSV and rename correctly. Verify that your CSV has no duplicate colors in it though or you will either get an overwrite warning from Automator, or it will fail in the absence of approving an overwrite condition for duplicates.



Tested: macOS Sonoma 14.0. Not tested with a NAS filesystem though.

Similar questions

10 replies
Question marked as Top-ranking reply

Oct 13, 2023 11:07 AM in response to AppleMarcus95

You second Ask for Finder Items should be Type: Folder, not Files.


This Automator application will process the CSV and rename correctly. Verify that your CSV has no duplicate colors in it though or you will either get an overwrite warning from Automator, or it will fail in the absence of approving an overwrite condition for duplicates.



Tested: macOS Sonoma 14.0. Not tested with a NAS filesystem though.

Oct 16, 2023 10:12 AM in response to AppleMarcus95

Tried removing the AppleScript components from this, and using bash or zsh directly? Add some echo commands to see the values in the symbols being used; ugly-debugging. You’re most of the way there to the shell already, of course. See if the code without Automator involved works.


If you want to create this parsing yourself, IFS is one of the most common ways, though it’ll hit issues because CSV is a simple-looking, but… less than robust… file format. I’d consider a library for parsing the CSV file too, as embedded spaces and other characters can derail the rename. (What VikingOSX posted is immune to most of those messes, though is sensitive to extra or escaped commas.)


Preference-wise, I’d probably use “${1}” and “${2}” here and not shift, too. shift is an ugly hack that works around some really old argument-parsing limits when 10 or more arguments are needed. Using “${1}” and “${2}” are clearer.


One of the more common requirements for these sorts of questions is creating your own file or photo storage database, and that gets gnarly for other reasons. If that’s what you are more generally doing here, moving to a database and away from Numbers or Excel, and avoiding CSV more generally, and utilizing Exif as appropriate, can be a more robust approach.


When I get back to the Mac, I’ll post up some code.

Oct 16, 2023 11:06 AM in response to MrHoffman

Ordinarily, I would use the Zsh shell, no shift operator, and a more hardened CSV row and column processing, but I wanted to stick with the OPs effort, and the Bash shell. The Automator application as I have written it works just fine on Sonoma 14.0 and Monterey 12.7.9 with the same CSV data shown by the OP. Historically, I have even used a filter on the CSV to trim CR from CRLF entries on Windows.


What AppleScript? ;-)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Mac Automater - File Rename Based of CSV

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.