Trying to Run a Bash Script on Launch of a Given Application and It Isn't Working

Hey all,

This is my first time using Keboard Maestro and I'm trying to get this to work.

I have a bash script that runs an autoimport from a github repository to a spaced repetition application I use, called anki. I'm trying set up a macro so that when that application opens, the script is run.

This isn't working for some reason.

Going through the support flow for "something expected isn't happening" (which is excellent, by the way, kudos to whoever designed it) I can confirm that when I launch anki the macro is triggered.

Separately, when I run the bash script from the terminal (simply typing "bash [the file path to the script]", it runs just fine.

So I don't know where the error could be. I do have it set to "display results in a window" which I would expect to open a terminal window (?). But it doesn't look like that is happening.

Here's my macro:

And in case it matters, here is the bash script:

#!/bin/bash

git clone https://6251c2653313ec9b48fff466b7530e4f137c8a99@github.com/Etyre/Roam_Backup.git
/usr/local/bin/ankify_roam add --deck="Incremental Reading" Roam_Backup/json/eli.json
rm -rf Roam_Backup

Does anyone know what is going on with this?

I'm wondering if you are assuming that you are in a certain directory when you are running the command.

For example, if you open a Terminal window, you will be in $HOME but when you run a shell from Keyboard Maestro it's probably in /

So maybe try something like this:

#!/bin/bash

cd "$HOME"

git clone https://6251c2653313ec9b48fff466b7530e4f137c8a99@github.com/Etyre/Roam_Backup.git

/usr/local/bin/ankify_roam add --deck="Incremental Reading" Roam_Backup/json/eli.json

rm -rf Roam_Backup

That might fix it.

1 Like

That did fix it!

Thank you!

1 Like

Great! Glad to help.

Welcome to the forums, hope you enjoy it here.

Wondering if the learning point is “the bash script isn’t in the same process”.