Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 515
Eyeball Avatar asked May 21 '13 20:05

Eyeball


People also ask

How do you run a command in a folder on a Mac?

Open the parent directory where your folder is located. Then single-click on the folder where you wish to launch a Terminal window, click on “Finder” followed by “Services,” and select “New Terminal at Folder.” Or you can simply press the keyboard shortcut that you assigned before.

How do I see information in multiple folders on Mac?

Once all of your files or folders are selected, use the keyboard shortcut Control-Command-I to access the Multiple Item Info window. Here, you can see the total number of selected items as well as their combined file size. Note the addition of the Control key to our normal “Get Info” shortcut.


1 Answers

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
like image 154
Chris Stratton Avatar answered Oct 12 '22 22:10

Chris Stratton