I have a couple of things to add.
Keyboard Maestro has quite a few options for handling errors in the Execute a Shell Script action:
If you're displaying the result of a shell script in a window you can simply turn on “Include Errors”.
You can stop KM from terminating the macro if there is an error in the shell script action.
You can also do something like this:
The first action allows the error to pass through by turning off the relevant items in the second highlight of the action/gear menu.
The second action is displaying the text token
%ActionResult%. This action normally returns "OK", but for a failed shell script like this one it might be something like:
Task failed with status 1
So should you wish you can put your error-handling outside the shell script action itself and use an If Then Else action with a text-condition.
That said – I like doing error-handling within the script itself, because you can make the output more predictable.
Absolutely true, but I'm not seeing the specific relevance here.
Grep on a Mac should be here and should not require the user to alter their path.
echo 'Unadulterated Keyboard Maestro $PATH:'"\n"
Unadulterated Keyboard Maestro $PATH:
grep is /usr/bin/grep
When I need to change the path of an individual action I usually add these paths to the default:
BUT – I find it much more convenient to add an environment variable to Keyboard Maestro's variables panel in the KM prefs.
Mine has grown over the years and won't be for everyone:
This environment variable will hold sway in all Execute a Shell Script actions, so you don't have to worry about about fixing the path on a per action basis anymore.
I've pulled my hair out a few times trying to troubleshoot a failed shell script, until I realized I hadn't emplaced a full path string.
So I finally got fed up – added the environment variable – and the sailing has been smoother ever since.