Hey TJ,
Well said.
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"
echo "$PATH\n"
echo "ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท\n"
type grep
OUTPUT:
Unadulterated Keyboard Maestro $PATH:
/usr/bin:/bin:/usr/sbin:/sbin
ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
grep is /usr/bin/grep
When I need to change the path of an individual action I usually add these paths to the default:
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:$PATH;
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:
Variable name: ENV_PATH
Contents:
/opt/local/bin:/opt/local/sbin:/Users/chris/perl5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin
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.
-Chris