Hello folks,
I'm here with another noob question that I wasn't able to find an answer for in the forum. Thank you so much for your kind help <3
What I'm trying to do
In this Execute Shell Script
Action, I'm using ack
, a grep
-like tool, to find a RegEx pattern in a local file:
(The DUSK
part will be replaced by a $KMVAR
when actually using the macro, but I'm using the text DUSK
instead of a variable to make debugging easier.)
What went wrong
ack -o '[0-9]{6}(?=,"name":"DUSK")' ~/Documents/Misc/Steam.json
|_____RegEx pattern________| |_______local file________|
When I run the above command in Terminal.app, ack
correctly returns a match as I expected. But when I run either one of these two below in the Execute Shell Script
Action:
#!/bin/zsh
/usr/local/bin/ack -o '[0-9]{6}(?=,"name":"DUSK")' ~/Documents/Misc/Steam.json
#!/bin/zsh
export PATH=/usr/local/bin:$PATH;
ack -o '[0-9]{6}(?=,"name":"DUSK")' ~/Documents/Misc/Steam.json
Keyboard Maestro simply reports the following in Engine.log
, which I find too vague to be helpful:
Action 15037406 failed: Task failed with status 1
Task failed with status 1. Macro “Trying” cancelled (while executing Execute Shell Script).
How I tried (and failed) to fix it
I tried running this in the Execue Shell Script
Action instead:
#!/bin/zsh
export PATH=/usr/local/bin:$PATH;
which ack
# ack -o '[0-9]{6}(?=,"name":"DUSK")' ~/Documents/Misc/Steam.json
and when then Action displays the results in a window afterward, the results are, as expected,
/usr/local/bin/ack
which, I believe, means KM's shell is indeed aware of what ack
is after I've exported the PATH. So I've really no idea what's going on here or what to do next.
Questions
I assume I can always avoid these issues by configuring the Action to Execute script file
instead of Execute text script
, but I'd really like to obtain a deeper understanding of what I'm doing wrong in the above. Learning is fun!
Thank you again for all your patience and time!