Need Applescript or Obj-C NSTask Loop

Discussion in 'Mac Programming' started by MorphingDragon, Sep 14, 2010.

  1. macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #1
    I need to rename some 1000+ sound files that were incorrectly ripped as .mp4 instead of .m4a. iTunes 10 and my iPod tries to play them as video files and its very annoying.

    I tried using BASH and SED but that didn't work too well and scripts online needed a text file of all the files and the renames.

    What I want -> A script that goes through a folder and its sub folders and rename any *.mp4 files to *.m4a
     
  2. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    Try this simple script in the console:

    for f in *.mp4; do echo $f; done

    Then modify it as needed. Renaming is done by using "mv".
     
  3. thread starter macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #3
    I get
    Code:
    *.mp4
    as my output, as it doesn't read into the sub folders. It works in individual folders with the songs.

    I'm surprised my RedHat training didn't cover something like this.
     
  4. macrumors 6502

    87vert

    Joined:
    Oct 7, 2008
    Location:
    Pittsburgh, PA
    #4
    Would automator be an option for this?
     
  5. thread starter macrumors 603

    MorphingDragon

    Joined:
    Mar 27, 2009
    Location:
    The World Inbetween
    #5
    Yes.

    You know, in all my years in Mac OSX this is the first time I've actually used Automator. Its very intuitive.
     
  6. macrumors 603

    Joined:
    Aug 9, 2009
    #6
    You might use */*.mp4 if all the files are one level deep. Otherwise, a 'find' command something like:
    Code:
    find /path/of/base/dir -name '*.mp4' -exec mv ..other stuff here.. \;
    
    See the man page for find.

    I think Automator is better in this case, though, unless you're starting with a tested 'find' command-line.
     
  7. ytk
    macrumors regular

    Joined:
    Jul 8, 2010
    #7
    Get Ruby to do the heavy lifting for you:

    Code:
    find  . -iname \*mp4 | ruby -ne 'puts "mv \"#{$_.chomp}\" \"#{$_.chomp.sub(/mp4$/, "m4a")}\""'
    Run that command in the root directory where the files are located. It should generate a series of mv commands that will do what you want. If you're happy with it, execute it by piping it to bash (you can use !! as a shortcut for the previous command):

    Code:
    !! | bash
     

Share This Page