From the grep
man page:
EXIT STATUS
The grep utility exits with one of the following values:
0 One or more lines were selected.
1 No lines were selected.
>1 An error occurred.
The command
ps ax | grep HandBrakeCLI | grep -v grep
...will return an exit code of either 0
-- the command succeeded because the HandBrakeCLI process was running -- or a 1
-- no lines were selected. If a shell script's final exit code is 1
then KM interprets that as the command failing -- which, to be fair, is usually correct. grep
is an exception to the *nix rule.
You can try for yourself in the Terminal -- $?
is the shell variable that holds the last exit code:
luggage:Steam nigel$ ps ax | grep MadeUpProcess | grep -v grep; echo $?
1
luggage:Steam nigel$ ps ax | grep MadeUpProcess; echo $?
615 s002 S+ 0:00.00 grep MadeUpProcess
0
luggage:Steam nigel$
You can mess around with the action's error options or maybe redirect the error to standard out in the script or something, but I think this is the easiest way round it:
ps ax | grep "MadeUpProcess" | grep -v grep || echo "Not found"
...which can be read as "return the process info for 'MadeUpProcess' if it is running, or (||
) return 'Not found' if it isn't". I only chose "Not found" because that's a self-documenting known value you can then test your KM variable for.
As to why you aren't seeing HandBrakeCLI
even when it is running? (One quick install later...)
Bad news is -- it works for me (macOS 10.14.6 test machine). I don't think it's a case-sensitivity issue, AFAIK Activity Monitor will use the same case as ps
, but you could check by using -i
on your grep
.:
ps ax | grep -i handbrakecli | grep -v grep || echo "Not found"
This is all testing with HandBrakeCLI run from either a Terminal command or a manually-triggered KM macro -- I'm wondering if your launch method might be changing things somehow? Try manual launching and see if you have the same issues, and let us know your normal launch method so someone can try and replicate the problem.