How to run Daniel Miesslers Fabric in a KM shell? github link in the body

Hello everyone,

I got the little things working, but not the starting of python programs via the shell, maybe someone knows better and has got fabric running.

I would like to monitor folders with Keyboard Maestro and if there are files in the folder, execute different patterns automatically with Fabric and preferably upload them directly to Airtable. Well, I'm not a developer, so I can't get Fabric to start in the Keyboard Maestro shell.

Does anyone know the correct path so that I can start Fabric? Or has any tips, thanks for the help

Fabric is an AI CLI pattern tool by Daniel Miessler.

Thanks a lot
Holger

The "correct path" will depend on your system and how you've installed things -- and also the correct path to what.

If you are going to use the "Execute a Shell Script" action you'll want the Wiki page to hand -- pay special attention to the "Quoting Strings" and "Path in Shell Scripts" sections -- most problems come from not feeding in paths correctly and not accounting for the fact that KM's environment is not the same as yours in Terminal.

If you're still stuck -- and I realise that "read the manual" isn't always helpful! -- post a command that is working in Terminal and the "Execute a Shell Script" version that is failing and someone might be able to spot the problem.

1 Like

First of all Nige,

thank you very much for your very appreciative and motivating contribution. It is not easy to answer questions from beginners again and again in a very calm and appreciative way. Yes, I got a bit lost and your comment grounded me again, thank you very much for that.

I was still able to solve the challenges with a pattern in the shell, the pipe works in the Apple shell and not in the KM shell. But that could also be due to the program fabric.

It works in the Apple shell:

fabric % cat /Users/holgergelhausen/Downloads/storm_gen_article_polished_german.txt | /Users/holgergelhausen/.local/bin/fabric --pattern extract_wisdom | create_keynote --output /Users/holgergelhausen/Downloads/storm_gen_article_polished_german_hg_var25.txt > /dev/null

Translated into the KM shell

/Users/holgergelhausen/.local/bin/fabric --text "$KMVAR_TextZuWisdom" -p create_summary | create_keynote --output /Users/holgergelhausen/Downloads/"$KMVAR_FileNameBase"_var23.txt > /dev/null

It works with one Pattern, but not with two. I can make a workaround.
It would be better if I could understand why this does not work.
Thank you Nige

It's probably because the shell in Terminal knows where to find Python without you (or Fabric) stating an explicit path -- the KM shell doesn't have the same $PATH environment variable to tell it where to look.

Try the following in Terminal and then in a KM "Execute a Shell Script" action set to "Display results in window":

whereis python

It's likely you'll get a path back in Terminal but just python: in KM.

The path to Python will depend on how you've installed it, but there's a good chance it is in /opt/homebrew/Caskroom/miniforge/base/bin:, so try the following in the KM action:

PATH=/opt/homebrew/Caskroom/miniforge/base/bin:$PATH
whereis python

If that works, great! Try adding the first line of that at the top of your fabric script. If it doesn't work then compare your shell's $PATH with KM's by putting

echo $PATH

...into each. There will be a lot of differences, you're looking for the entry the same as the start of the result you got from Terminal's whereis.

If all that is working, try the exact same command as you are using in Terminal in the KM action -- cating in a known good file will show if fabric is working, at which point you'll need to look at the KM variables you are passing in.

1 Like