MacOS – How to adjust a script that works in the Terminal but fails in Automator

automatormacosscript

I have been piecing together a shell script to use FFmpeg to validate video files in a folder and create a log file.

When run in the terminal from that folder, it works fine. When I incorporate it into Automator to use as a service, it fails to create the log file correctly.

It looks like the syntax I'm using causes an issue in Automator, and it's failing as it invokes FFmpeg. How do I adjust my script in Automator to give me the same result as I got in the Terminal?

Here is the script in Automator:

for f in "$@"
do
    echo "$f"
cd $f
pwd
find -E ./ -regex '.*(.MOV|.MXF|.mp4|.MTS)$' -exec ffmpeg -v error -i {} -map 0:1 -f null - 2>error4.log \;
done

And the output from the log file:

find: ffmpeg: No such file or directory

Automator Screenshot

Best Answer

This is because Automator doesn't use your interactive shell's path. You need to specify the location of ffmpeg.

  1. In Terminal, run:

    which ffmpeg
    
  2. Replace the ‘ffmpeg’ in your Automator shell script with the output of this command.