PDA

View Full Version : Need Applescript or Obj-C NSTask Loop




MorphingDragon
Sep 14, 2010, 03:39 AM
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



gnasher729
Sep 14, 2010, 04:22 AM
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

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

MorphingDragon
Sep 14, 2010, 04:52 AM
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".

I get *.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.

87vert
Sep 14, 2010, 05:51 AM
Would automator be an option for this?

MorphingDragon
Sep 14, 2010, 06:00 AM
Would automator be an option for this?

Yes.

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

chown33
Sep 14, 2010, 10:42 AM
I get *.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.

You might use */*.mp4 if all the files are one level deep. Otherwise, a 'find' command something like:
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.

ytk
Sep 14, 2010, 06:24 PM
Get Ruby to do the heavy lifting for you:

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):

!! | bash