Possible to use a variable in an if script action?

Howdy folks,

Quick question on the If action: can a variable can be used inside the shell script text option?

For instance, in the screenshot below, I use a variable in a curl ... | grep command, and it doesn’t work... but I’m curious if I’m just doing something wrong or this simply isn’t a feature.

I’ve tried this method... (Action Screenshot: click to expand/collapse)

I’ve also tried the following... (Action Screenshot: click to expand/collapse)

Any thoughts are appreciated, thanks!

Hi, @cdthomer. Interestingly with my testing, Include No Variables was selected by default for the The shell script text script box. When I change it to Include All Variables, the script works as expected.


Here's my test macro:

Download: Test Script Condition.kmmacros (3.1 KB)

3 Likes

Yes. Variables are not sent to scripts in conditions by default, so you have to include the desired variable in the menu on the left of the script.

3 Likes

Thank you both for the clarification, I didn’t even think about checking for variable inclusion!

1 Like

That raises another question. If one needs only one variable in the shell script, is there any reason one might want to select the specific variable versus Include All Variables?


On a related note, I noticed in the wiki screenshots that the dropdown menu does not exist.


I want to complement @peternlewis: The contextual help provided for Keyboard Maestro actions is incredibly helpful!

1 Like

Good question... I imagine if you were to include all variables, it might slow down the macro’s execution (albeit by a marginal amount), but I don’t really know for sure.