Question about using Automator and Apple Script to do something

Discussion in 'Mac Apps and Mac App Store' started by KBS756, Nov 9, 2010.

  1. KBS756 macrumors 6502a

    Joined:
    Jan 27, 2009
    #1
    I have a bunch of images in a folder and say I want to do something like the following to them

    The original image name is

    2575-W.jpg

    Say I now want to take the first 4 digits and and add 645 to them to get 3219

    how would I do this in automator any other mac application


    (I have like 5,000 photos I need to do this for)

    Thanks in advance
     
  2. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #2
    Could do this with a simple shell script.

    Is every file in this folder named dddd-W.jpg (where each d represents a digit)?

    Do you want to add 644 or 645? In any case you want to add the same number to each dddd?
     
  3. KBS756 thread starter macrumors 6502a

    Joined:
    Jan 27, 2009
    #3
    YES I want to add each number to the 4 digit number and replace that in the file name over the original number

    can you let me know how to do that ?

    thanks
     
  4. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #4
    I can tell you how to do it, but only if you can precisely answer each of the three questions I asked. Otherwise you're likely to end up with names you don't want.
     
  5. KBS756 thread starter macrumors 6502a

    Joined:
    Jan 27, 2009
    #5
    Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B117 Safari/6531.22.7)

    Ok the folder has pictures that have 4 digits to start and have a couple variations behind them -w.jpg -y.jpg -w-btpz.jpg like that

    And yes I Want to add 645 to all the pictures names exactly that to all of them

    Thx in advance
     
  6. LPZ macrumors 65816

    Joined:
    Jul 11, 2006
    #6
    OK. This should work.

    Open Terminal (in Utilities).

    In Terminal, type the following, leaving a space after the d. Don't press return yet.

    Code:
    cd
    Now drag the folder containing the files and drop it into the Terminal window. This will append the folder's path to the cd command.

    Now click on the Terminal window to make it active and press return.

    To check that things have gone correctly, type

    Code:
    ls
    in Terminal and press return. (That's lowercase-l and s.)

    You should see a listing of the files, still with their old names.

    If so, then copy and paste the following into Terminal and press return.

    Code:
    mkdir newdir; for file in *; do oldindex=${file:0:4}; newindex=$((oldindex+645)); cp -p $file ./newdir/$newindex${file:4}; done
    You should get a new folder named newdir inside your folder. Inside that folder should be the renumbered files.

    Don't worry about the following, which will appear in Terminal:

    Code:
    cp: newdir is a directory (not copied).
    In any case, the original files are not being deleted, just copied and renamed.
     
  7. KBS756 thread starter macrumors 6502a

    Joined:
    Jan 27, 2009

Share This Page