MacOS – Automate Duplicating and Renaming Images

automatorimage editingmacos

I've got an image and I need to duplicate it 800 times but add a new prefix every time I duplicate it. I've got the prefixes in a CSV file (or spreadsheet) and I'm wondering if there's a way that I can have Automator (or some other automation) program duplicate the image but rename the image with the different prefixes.

I'm aware of how to duplicate multiple images with the same prefix but is it possible to duplicate one image multiple times with different prefixes. Thanks for your help!

Best Answer

  • I whipped up a quick script that will copy the image for you (it will work with any type of file actually) and rename it from a plain text file with one prefix per line.

    #!/bin/bash
    file=$1
    prefixes=$2
    filename=`basename "$file"`
    while read line
    do
        cp $file "$line-$filename"
    done < $prefixes
    

    Put that into a text file, save it as copier.sh. Then in Terminal, run chmod +x copier.sh (make sure you’re in the same directory as where you saved the file, ideally the one with your images in it). Then run ./copier.sh myimage.jpeg prefixes.txt and you should have a bunch of copies with different names.

    The prefixes.txt file (or whatever you want to name it) should have one prefix per line (which should be easy to get by copying and pasting from your spreadsheet).


    Updated Version With Folders

    #!/bin/bash
    file=$1
    prefixes=$2
    filename=`basename "$file"`
    foldername=${filename%%.*}
    if [ ! -d "$foldername" ]; then
        mkdir "$foldername"
    fi
    while read line
    do
        cp $file "$foldername"/"$line-$filename"
    done < $prefixes
    

    That will create a folder with the same name as the original file (if it doesn’t already exist) and place the copies in it.