Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Rename files with random names

Hi all -

I have a folder of 600 images to go on a digital photo frame. The digital photo frame always plays in the same order, so I want to randomize the files before I put them on the frame.

I tried using automator's batch rename, but that won't randomize the files.

Anyone know of a software utility to do this easily? I am unfamilar with scripting, so any solutions i've found online that use scripting are foreign to me..

TIA

17" Macbook Pro, Mac OS X (10.5.1)

Posted on Feb 28, 2008 4:07 PM

Reply
Question marked as Best reply

Posted on Feb 28, 2008 6:20 PM

ok, paste the following into script editor and save it as an application.

----------------------------------


tell application "Finder"
set fol1 to folder "1" of (path to desktop)
set fol2 to folder "2" of (path to desktop)
set theNum to number of items in fol1

repeat with i from 1 to theNum
set this_item to some item of fol1
set fname to name of this_item
set name of this_item to (i as text) & fname
set x to (first item of fol1 whose name is (i as text) & fname)
move x to fol2
end repeat
end tell



--------------

This will work as follows. Say you have folder on the desktop named 1 with 600 images.
make a folder named 2 on the desktop and run the script. It will move your images from folder 1 to folder 2 and add a random number between 1 and 600 to the front of their names. The script can be easily adjusted to work on other folders but since you don't know apple script I suggest you create folders 1 and 2 on your desktop, move all your images to folder 1 and run the script. You can run the script by pressing the "run" button in script editor or by double-clicking on the saved application.

Message was edited by: V.K.
9 replies
Question marked as Best reply

Feb 28, 2008 6:20 PM in response to Carl Sundermann

ok, paste the following into script editor and save it as an application.

----------------------------------


tell application "Finder"
set fol1 to folder "1" of (path to desktop)
set fol2 to folder "2" of (path to desktop)
set theNum to number of items in fol1

repeat with i from 1 to theNum
set this_item to some item of fol1
set fname to name of this_item
set name of this_item to (i as text) & fname
set x to (first item of fol1 whose name is (i as text) & fname)
move x to fol2
end repeat
end tell



--------------

This will work as follows. Say you have folder on the desktop named 1 with 600 images.
make a folder named 2 on the desktop and run the script. It will move your images from folder 1 to folder 2 and add a random number between 1 and 600 to the front of their names. The script can be easily adjusted to work on other folders but since you don't know apple script I suggest you create folders 1 and 2 on your desktop, move all your images to folder 1 and run the script. You can run the script by pressing the "run" button in script editor or by double-clicking on the saved application.

Message was edited by: V.K.

Feb 28, 2008 5:14 PM in response to V.K.

I have a folder with 600 images. People emailed these to me for a photo frame for a birthday gift. Therefore, there is no ryhme or reason to the existing naming scheme. Some are IMG_xxx from digital cameras, some are SCANXXXX from scanners... But the frame always plays those in alphabetical order. So, person 1's images are always first. I want to take all those files and give them new names, all mixed up.

While I'd prefer to have the files renamed to img0001, img0002, etc, a simple addition to the file name will do as well, so I think the applescript would work, but I have no idea how to run something like that.

Feb 28, 2008 7:09 PM in response to V.K.

Thanks for the help, but that only kind of works. It looks like it moved all the files, but then didn't delete the old ones. So now I have 1200 files in that folder, not 600.

I'm really looking for an easier way to do this too... I used to be able to do it on my old PC with a software app, but I can't find anything for the mac. Hmmm..

Well anyway, thanks for trying.

Feb 28, 2008 7:24 PM in response to Carl Sundermann

sorry, I don't get it, you got 1200 files in what folder? I tested the procedure and it works exactly as it should on my computer so it should work on yours in exactly the same way. Just to make sure, you start with 600 files in folder 1 and empty folder 2, you run the script and you end up with empty folder 1 and 600 renamed files in folder 2.
Is this what you did? I can not imagine how you can end up with 1200 files in the same folder.

Feb 28, 2008 8:35 PM in response to V.K.

Here's what I do:

Folder 1 has 600 jpg files.
Folder 2 has nothing.
Both are on the desktop.

When running the script, it moves all files from folder 1 to folder 2, then takes a random file and adds 1Filename, 2Filename, etc, but does not delete the original. So if I have one called SCAN001, it might take that and make it 1SCAN001, but then does not delete SCAN001. There are now two copies of that file in folder 2, one called SCAN001, and one called 1SCAN001. Does that make sense?

Sorry for causing problems here, but I've run it a couple times and thats what happens.... I've even started over with a new applescript. I'm using Leopard, latest update...

Feb 28, 2008 9:05 PM in response to Carl Sundermann

this is so strange I don't know what to say. It works as it should here and i really can not understand why it would do what you describe.
Let's simplify the procedure.
put your files in folder 1 on the desktop and run the following script.
It should rename them all and they should end up back in folder 1.

-------------------------------------------------

tell application "Finder"
set fol1 to folder "1" of (path to desktop)


make new folder at (path to desktop) with properties {name:"tmp"}
set fol2 to folder "tmp" of (path to desktop)
set theNum to number of items in fol1

repeat with i from 1 to theNum
set this_item to some item of fol1
set fname to name of this_item
set name of this_item to (i as text) & fname
set x to (first item of fol1 whose name is (i as text) & fname)
move x to fol2
end repeat
move files of fol2 to fol1
delete fol2
end tell

----------------------
I do hope it works this time!

Rename files with random names

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