Automator to rename files based on CSV list

Started by DCurry, February 10, 2016, 10:04:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DCurry

As previously mentioned, I'm not a scripter. Or an Automator guru. But some of you are, so here's what I'm looking for help with this time:

I need a way to rename a bunch of files with a person's name from an Excel list or CSV. I use SmartStream to generate variable data certificates, but it can't intelligently name them as it creates. So I take the whole PDF, open it in Acrobat and use Split Pages to generate one PDF for each page. The problem is they are named FileName_1.pdf, FileName_2.pdf, FileName_3.pdf, etc.

So, the number in the new FileName does correspond to a field in my CSV (Sequence), but I want to pick up another field (Full Name) and rename to that value.

Result would be files named JohnDoe.pdf, SteveSmith.pdf, JoeCool.pdf, etc.
Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!

Joe

So just to be clear. You want something that will read the 'Full Name' field in the .csv and name the PDF's to that value? So the single page PDF's, named with _1, _2, etc correspond with the value of the 1st value in that field, 2nd value in that field, etc...? Or does it matter the order of the naming?
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

DCurry

Exactly. A field in the data says "FileName_1" and another field in the same record says "JohnSmith". Old name of PDF is "FileName_1.pdf" and need to rename to "JohnSmith.pdf".
Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!

Joe

So lets just say for example the PDF has 10 pages in it to keep it simple and the original PDF is named myfile.pdf and when you split that out into singles page PDFs they are named myfile_1.pdf, myfile_2.pdf, etc...?

There is a field in all 10 records called myfile_1, myfile_2, etc...?

So you want the pdf named myfile_1.pdf renamed to the corresponding 'fullname' field in the record that has the field value myfile_1?

Then you want the pdf named myfile_2.pdf renamed to the corresponding 'fullname' field in the record that has the field value myfile_2? And so on?

Kind of confused how the name of each single page PDF got into your excel/csv?
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

DCurry

That is all correct, Joe.

As for the last point of confusion, in every mailing list we have a Sequence column used to keep it in presorted order if anyone drops the pile. It simply starts at 1 and goes in numerical order from there.

So, if I have 10 records and end up with a 10page PDF, I split it to end up with 10 single-page PDFs. At this point, the actual file name doesn't matter except for the fact that Acrobat adds "_1", "_2" etc. to the end. I can then use a utility called FileRenamer to simplify the PDF name so it is the digit only, so now my PDFs are named 1.pdf, 2.pdf, 3.pdf etc.

The 1, 2 and 3 correspond to the Sequence column. So, the name of the original PDF is not really in the CSV, but I just rename the PDFs in sequence to fake it out.

Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!

Joe

ahhh OK. That makes sense.

So one other question....do you want it to get the value from an excel file or the csv? Do you always have one kind, both kinds or sometimes you only have one? It's easier to parse a text file than an excel file is why I ask.

Do you have a sample .csv or excel file you can post?
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

DCurry

CSV file would be fine - that's what we use for all our VDP work.

Here's a sample file. My actual files will have more columns and will probably have different named headers, but I should be able to tweak that on my own.
Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!

Joe

 :lmao:

Steve Buttsniffer

I think I've worked with him before!
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

DCurry

Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!

Ear

Alright, who wants a mustache ride?

Wait, what?
"... profile says he's a seven-foot tall ex-basketball pro, Hindu guru drag queen alien." ~Jet Black

David

Prepress guy - Retired - Working from home
Livin' la Vida Loca

Joe

#11
Dan, try this applescript. Run it, point it at the .csv, then point it at the folder with the PDF's. Worked on my test with 4 PDF's and your test CSV file.

set the_list to (read (choose file with prompt "Choose the file that contains the student ID's:"))'s paragraphs
set source_folder to (choose folder with prompt "Choose the folder with the .jpg's to rename:") as Unicode text
tell application "Finder"
 repeat with this_para in the_list
 set {source_file, new_name} to my string_to_list(this_para, ",")
 try
 set name of ((source_folder & source_file & ".pdf") as alias) to new_name
 on error e
 activate
 display dialog e buttons {"Cancel", "OK"} default button 2 with icon 0 giving up after 5
 end try
 end repeat
end tell

on string_to_list(s, d)
 tell (a reference to my text item delimiters)
 set {o, contents} to {contents, d}
 set {s, contents} to {s's text items, o}
 end tell
 return s
end string_to_list

Edited to ad: You have to remove the first line of the .csv which are the label headings.
Mac OS Sonoma 14.2.1 (c) | (retired)

The seven ages of man: spills, drills, thrills, bills, ills, pills and wills.

DCurry

Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!


DCurry

Joe, that does the trick - thanks a ton!

Swampy, I'll check out your solution, too. Might be even simpler since it occurs straight from Acrobat.
Prinect • Signa Station • XMPie

Build a man a fire, and he'll be warm for a night. But set a man on fire, and he'll be warm for the rest of his life!