Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am using the command mac in terminal to compress and decompress Monkey's Audio files. However, I want to find a way to do it to more than one file at a time. Is there a trick for the mac program that I don't know, or is there another program that can help?

I'm stuck using the Window's GUI under WINE. Help free me from this :)

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

No, mac does one file at a time, so you have to work around it.

Assuming the files you want to encode/decode are in specific folders, or sub-folders, and not arbitrary paths, you can do it with a combination of find, sed and xargs.

For example, to encode all WAV files in a specific folder and all its subfolders, with the output files simply having the APE extension, using the fast -c1000 preset, you would type:

find ~/path/to/folder -name *.wav | sed 's/....$//g' \
   | xargs -I MACFILE mac "MACFILE.wav" "MACFILE.ape" -c1000

Explanation:

  • find finds all files with the wav extension in and under the given path, and outputs them.
    • You can use `pwd` (with the backticks) as shorthand for the current folder.
    • Add the argument -maxdepth 0 to stick to the current folder only and not go into subfolders.
  • The sed expression deletes (i.e. replaces with "blank") the last four characters of each filename returned by find, which is the extension .wav or .ape
  • xargs feeds each filename piped in to the mac command.
    • The -I MACFILE tells xargs to replace each occurrence of MACFILE with the input (filename); this way we get files with proper extensions and not .wav.ape, etc.

To decode within the current folder only, and output to a custom folder, for example:

find `pwd` -name *.ape -maxdepth 0 | sed 's/....$//g' \
   | xargs -I MACFILE mac "MACFILE.ape" "/home/ryan/decodes/MACFILE.wav" -d

Note: find is one of those utilities that are almost limitless (see man find). With the right -exec and -printf options (and maybe more), find may alone be sufficient without needing the sed and xargs, and I'm sure someone will point that out :) . But I find this easier to explain and understand.

share|improve this answer
    
it works!!! Sorry for the delayed response, I keep forgetting to accept the answer! Works with no problems, excellent answer! :) –  Ryan McClure Jul 12 '12 at 5:29
    
To be honest, the reason I was asking was because I needed to batch decompress .ape to .wav, then to .flac. I had a public domain set of music that I had downloaded, but it was .ape. So, i honestly wanted to put it to .flac. However, I wanted to know a batch way. And I figured, while I was at it, why not have a question that dealt with batch compression and decompression? ;) Help the rest of the community as I figure out my answer. –  Ryan McClure Jul 12 '12 at 18:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.