[SOLVED] FFmpeg Command Working in Terminal But Won't Run in KM

I am having trouble running a shell script from Keyboard Maestro that worked perfectly on another laptop. I recently got a new laptop, migrated everything across, but something is not working quite right.

The shell script I have is one that is triggered when a file gets added to a folder. It then runs an ffmpeg command, converting the video to another folder.

The shell script looks like this:

ffmpeg -i "$KMVAR_FileName" -filter:v fps=30 -preset fast -crf 28 "$KMVAR_FileNameNew"

The KMVARs have valid values.

If I run this script in terminal, it does exactly what it should do:

ffmpeg -i a.mp4 -filter:v fps=30 -preset fast -crf 28 b.mp4

But when the folder trigger happens (new file added) and it tries to run the shell script with the KMVARs in, it errors. The error log shows this:

2022-10-28 22:42:46 Execute a Shell Script failed with script error: text-script: line 1: ffmpeg: command not found. Macro “FFMpeg iMovie File” cancelled (while executing Execute Shell Script).

Now, I know that ffmpeg is installed, and I know it works in Terminal. But clearly there's something I've missed, and I have no idea whether this is a KM issue or something else. Given that this works perfectly on my old laptop, I assume it's an environment thing, a setting I have not yet applied to the new laptop.

Can anyone tell me what I need to do to get KM to run this?

You haven't provided the full path to ffmpeg

See:

action:Execute a Shell Script [Keyboard Maestro Wiki]

  • The $PATH environment variable you may have set in Terminal is not used.

(The search paths defined in the Terminal.app shell instance are not defined in the vanilla shell instance used by Execute Shell Script)


In Terminal.app, you can, of course find the full path with an incantation like:

which ffmpeg

and the full path may be something like

/usr/local/bin/ffmpeg

OK, cool. So typing which ffmpeg told me it was here:

/opt/homebrew/bin/

Updated the shell script and now that works.

However, what I don't understand is why this worked WITHOUT the full path on my old laptop. I figure I must have run some other command that somehow set the path. It's fine though, I can simply add in /opt/homebrew/bin/ and. it works, but I wonder what I did last time for it to not to need that.

1 Like

Oh, and of course ... thank you!

I’d guess the path was in your KM_VAR or echo path

1 Like

You probably did do it last time -- and, depending on how you migrated to your new laptop, that path may still be in your KM vars. But if you've upgraded from an Intel to Apple Silicon then your homebrew installation path has changed, from /usr/local/bin to /opt/homebrew/bin.

2 Likes