Search code examples
macoscommand-lineimage-compressioncommand-line-tool

OSX: Execute same command on all files within a folder


i am using a command-line tool called TMX (https://github.com/tonybeltramelli/TMXResolutionTool) I want to execute this command on every .png file in a certain folder. How can i do that?

This is how it is used:

TMXResolutionTool <tmx path> <resize ratio>
TMXResolutionTool <image path> <resize ratio>
TMXResolutionTool <image path> <new width> <new height>

Cheers.


Solution

  • find <path> -name "*.png" | xargs -Irepl TMXResolutionTool repl <ratio>
    

    If you need to run all those commands in order on each file before moving to the next, a small bash script may be clearer

    find <path> -name "*.png" | while read f ; do 
    TMXResolutionTool $f <resize ratio> ; 
    TMXResolutionTool $f <resize ratio> ;
    TMXResolutionTool $f <new width> <new height> ; done