Benches macOS

9

Rename files with random names

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

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

9 replies

Sign in or join Beachball Help to reply.

  1. 0

    V.K.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  2. 0

    V.K.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    not quite sure what exactly you want. If you want to randomize the names of the files for example by randomly adding a number to their names, that's easy to do with apple script. Is that what you want? I can help you with the script.

  3. 0

    Carl Sundermann

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  4. 0

    Carl Sundermann

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  5. 0

    V.K.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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.

  6. 0

    Carl Sundermann

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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...

  7. 0

    V.K.

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    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!

  8. 0

    tnaseem

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Many thanks for the script. I was looking for the same thing.

    Your initial script worked fine here. 🙂 Looking at it, I can't see how the original poster was having problems with it. Very strange...

    Cheers,

    Taz

  9. 0

    Marakel

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    I just have to say, LOL.