Executing a Shell Script action

Hi,
I have several repetitive terminal command tasks performing every day on my Macbook and I would like to use KM macro for each command instead of using the following terminal commands:

  1. to crop a video file: ffmpeg -i video.mp4 -ss (from time) -to (till time) -c copy name.mp4
  2. to combine a video file with the same video and audio encoding together: ffmpeg -f concat -i file1.txt -c copy name.mp4
  3. to resize a video file to a standardized 240:426 size: ffmpeg -i output1.mp4 -vf scale=240:426 name.mp4
  4. Finally, to convert a JPG screenshots to a webp file: cwebp original.jpg -q 1 -o name.webp
    P.S.: the full path in my case is: /opt/homebrew/bin/ffmpeg
    Any help is greatly appreciated

An Execute a Shell Script action can execute all of those.

Where is the file? Is it always the same location, and the same name?

If so, it could be something like:

cd ~/Documents/myfile
/opt/homebrew/bin/ffmpeg -i video.mp4 -ss (from time) -to (till time) -c copy name.mp4
/opt/homebrew/bin/ffmpeg-f concat -i file1.txt -c copy name.mp4
/opt/homebrew/bin/ffmpeg-i output1.mp4 -vf scale=240:426 name.mp4
cwebp original.jpg -q 1 -o name.webp

You might need the full path of the cwebp tool too.

But I expect there are other variances in the names of the files that you haven't mentioned so that may yet need dealing with.

1 Like

Thanks for your reply,
All files, by default, would be located on my desktop folder. And they would all have the same name since I would convert my files one by one.
Since I haven't really executed a single shell script in Keyboard maestro app, I really need step by step guidance. So for instance, under "Execute shell script" field I'd include for question number 4) above the following command:
Macbook-name/opt/homebrew/bin/cwebp my-screenshot.jpg -q 1 -o converted-photo.webp
I did that but nothing has happened... I noticed I need to include as well the following:
"When you execute a shell script from other apps, like Terminal.app, the shell does not have access to the Keyboard Maestro Engine environment, and thus it does not know anything about Keyboard Maestro Variables.
In order to access Keyboard Maestro Variables in these scripts, you must use a tool like osascript."
Any advice?

No.

Just

cd ~/Desktop
/opt/homebrew/bin/cwebp my-screenshot.jpg -q 1 -o converted-photo.webp

In the action, turn on Include Errors, and display the results in a window so you can see the errors, otherwise you have no idea what is happening or what is wrong.

1 Like