Mac Automator - mass keywords rename

formosaz

Active member
Jan 28, 2008
1,054
2
38
Recently i have been playing with mac automator and found out to be really cool.

I can batch rename file with just a click of a button. But the shortcoming is that it's able to rename 123.jpg to abc-1.jpg etc

I was wondering if anyone know a way which i can batch rename say
1.jpg , 2.jpg etc from .txt or .csv to kw1.jpg , kw5.jpg etc ...

hope it's not too confusing ..

any help would be appreciated :)
 


If you're happy to play around on the command line, this should be very simple with Python or similar

Assuming, you have the same number of numbered files as you have keywords and file extensions are all ".jpg":

Code:
import os

keywords = ['black', 'white', 'blue', 'red']

for index in range(len(keywords)):
    os.rename(str(index + 1) + '.jpg', keywords[index] + '.jpg')
 
thank you for the response but automator is just some click

and i have zero knowledge in python :(
 
Are you wanting to rename keywords that are file names? Or do you want to rename the files and extensions?

And how exactly are you deciding how to rename these files/keywords because, perhaps it's me, but I don't see how the original and new files/keywords have any relationship ("123.jpg to abc-1.jpg", "1.jpg , 2.jpg etc from .txt or .csv to kw1.jpg , kw5.jpg").

I am confuse.
 
sorry... it's the file name ...say i have

1.jpg
2.jpg
3.jpg
..
..

i want to pulling from csv.

col 1 col 2
1.jpg xyz.jpg
2.jpg qwqe.jpg
3.jpg 451.jpg
.. ...
.. ...

so basically all the column1 file would be rename to column 2 file name
 
Here's the Ruby solution.

Code:
filename = "text.txt"
File.read(filename).lines.each do |line|
  old, new = line.split
  File.rename(old, new)
end
or just in one line:

Code:
File.open("text.txt").lines.each { |line| File.rename(*line.split) }
If this is your `text.txt`:

89.png


Make sure everything is in the same folder and just run the ruby file:

8b.png
 
Scala version:

Code:
import java.io.File
val lines = io.Source.fromFile("files.txt").getLines
for (line <- lines) {
  line.split(" ") match {
    case Array(a, b) => (new File(a)) renameTo (new File(b))
  }
}
 
Code:
import java.io.File
val lines = io.Source.fromFile("files.txt").getLines
for (line <- lines) {
  line.split(" ") map (new File(_)) match {
    case Array(a, b) => a renameTo b
  }
}
Maybe better? Sorry, I'm done now.
 
If you're happy to play around on the command line, this should be very simple with Python or similar

Assuming, you have the same number of numbered files as you have keywords and file extensions are all ".jpg":

Code:
import os

keywords = ['black', 'white', 'blue', 'red']

for index in range(len(keywords)):
    os.rename(str(index + 1) + '.jpg', keywords[index] + '.jpg')

Code:
enumerate
 
as im a (shamed to be) coding loser - im trying trying to get time to sit my ass down and learn big time - its like the one skill i kick myself daily for now having and want bad.... and know i can think this way -

anyway writing though cause - being mac user longtime I know some great utilities (not command line) that do just about anything you can come up with for renaming and related...

the absolute best ever is an app creatively named:

better rename 9

publicspace.net - Better Software for Macintosh and Windows

they have a few other sick apps - big mean folder machine, and A Better Finder Attributes too

im with you on the automator thing - its actually pretty cool the more i try to muck around in there.

there is a web automator for mac but its not designer for us marketer types thus not even as useable - fake (worth having still)

(and dont gimme shit you awesome coders who think such a tool as ubot is likely tinker toy - hell it get shit done)... but im using that on my one annoying to own pc (but it is actually about the best pc experience i admit ive ever had, samsung 940x ultrabook, screen is friggin 3000px wide, more than my 3 retinas im addicted to, ... newly gotten for this and few other things... still think windows sucks ass whatever the version, but im mostly trying to get a rise out of the (i assume) mostly pc fanfaggots here (yeah ive used macs since i was in grade 6, doing desktop publishing, then cdroms, then web and video and animation and now somehow bloody seo... lol.... but ive used mac forever a good fuck of a while ago and its always been awesome... fanboy whatever i may be i just like high quality, this samsung is the closest thing ive ever seen to it in a wintel)... some shit has indeed been going downhill since steve's passing but for now they are hanging pretty tight, damn the new macpro relieved my worry they were gonna ignore pro users (hot ass machine too)

ok nuff of all that, hope that helps a bit


unagi+++++++