Run Single Command on Finder Selection

Here is a macro that will let you process the Finder Selection and then run a single shell command applying to all the selected files. It gathers the Finder Selection together into a newline-delimited variable (Paths), and then feeds that variable to the shell script as STDIN. Then it uses a trick from Mac OS X Hints to convert the line endings into null (\0) characters, and then pass them to xargs to build the command line.

The command currently is just ls -l, but it could be anything, and since the paths are inserted at a specified location, you could have an output file in the command as well if desired.

Run Single Command on Finder Selection.kmmacros (2.7 KB)

4 Likes

I have used this in this macro:

It seems the list of files I pass to the command comes in the Date created order.

In this case with my pdf-files, I would like it be merged in alphabetical order.

How do I change the order?

The files are ordered in whatever order the Finder decides to return them in.

If you want them ordered in a specific way you will need to sort them yourself - read all the file paths and put them all into a variable, then sort the variable, then read all the lines from the variable and process the files that way.

1 Like

Of course. I will try it.

It has been solved now with the sort terminal command.