Executing a shell script that displays a chooser UI

Hi all,

I've recently started using macOS for work and, coming from Linux, am looking to replicate as much of my setup regarding keyboard shortcuts etc. as possible. I'm currently trialling KM and it seems to have everything I need (and more!).

However, I am having trouble executing some of my scripts within an action. I've narrowed the issue down to the presence of the choose command in the script which simply provides the ability for the user to choose one of a number of options using a nice UI (similar to Linux's rofi -dmenu command). (I realize that KM has the "Prompt with List" action but I'm trying to keep everything within the script and just use KM to trigger it.)

As the simplest example, I have the following test script:

#!/usr/bin/env bash
echo "Start"
ls | choose
echo "End"

If I run this in the terminal (and choose test-script.sh from the displayed list of files), it outputs:


but if I test the action within KM, the list of files is not displayed and the output of the script (as displayed in the results window) is:


Can anyone help me understand why this is happening and whether there's anything I can do to make it work?

Thanks in advance!

Welcome to the KM forum!

First, have you read the KM wiki page about executing shell scripts here action:Execute a Shell Script [Keyboard Maestro Wiki] ?

If you have then you’ll know that KM executes scripts in a non-interactive shell whose default path is very different to the one you’ll encounter in Terminal.

Next, there are loads of pitfalls when executing shell scripts in KM which even a cursory search of the forum readily reveals. Consequently it is impossible to say for sure what your problem might be without actually seeing the macro you are having issues with.

It would be worth a few minutes of your time to review these:

Since I’m not at my Mac I can’t offer much further assistance, but hopefully you can post your macro and someone else will jump in!

1 Like

Thanks for the tips, @tiffle - turns out it was, indeed, a path issue :slightly_smiling_face: