Feature Request: Add a "Pass Finder Selection to Terminal Shell as a Variable" Action

I'd love if it where easier to pass something to terminal, example:

  • Pass selected file(s) in Finder to Terminal shell as a variable in script
    could be much simpler for ocasional uses, and have documentation.

a "batteries included" action, so to say.

my 2c.

Hey @hello,

Do you mean the Terminal.app?

Or do you mean the Keyboard Maestro Execute a Shell Script action?

Personally I'd like for @peternlewis add a text token for the %FinderSelection%.

This would simplify or solve a number of things.

In the meantime you'll have to live with something like this:

Return Finder Selection as POSIX Path List v1.00.kmmacros (7.2 KB)

To use this you can do something like:

Process Finder Selection with Execute Shell Script Action v1.01.kmmacros (8.3 KB)

Now then – that's NOT how I do this task in my own work.

If I'm working in an Execute a Shell Script action I'd rather keep all of my work consolidated if possible, so I'll do something like this:

Process Finder Selection with Execute Shell Script Action v2.01.kmmacros (7.8 KB)


Thanks to @JMichaelTX for picking up on a couple of issues with my macros.



Thanks! great stuff as usual cc

yes, great way to put it, a token would be very useful indeed!

1 Like

Actually KM has already highly automated much of what you are asking for.
For example:

  1. For Each action using a Finders Selection collection.
  2. In the Execute a Shell Script action there is an option to pass the script, as stdin, the data in a KM Variable, Clipboard, even text:
  3. In the Execute Shell Script, directly reference KM Variables:
    • image

Even if @peternlewis provided us with a text token for the %FinderSelection%, it would not work inside of the shell script, since AFAIK shell scripts do NOT support any tokens.

I just wanted to make sure you, and others, are aware of the current support KM provides for shell scripts.

1 Like

Assuming you have a single thing selected in the Finder, then:


sets the variable FinderSelection to it.

I think so; it'd save people a good deal of work.

Here's a canonical Keyboard Maestro macro to work with the Finder selection.

I've added a counter and a line-count filter to demonstrate both in action.


Save Path(s) of Selected Item(s) in the Finder to a Variable v1.00.kmmacros (13 KB)