Converting videos in the background using automator and handbrake

applescriptautomator

I am trying to automate the process of video conversion using handbrake and automator.

Here is the script that i am using in Run Shell Script action of Automator Folder Action:

for f in "$@"
do
    Applications/HandBrakeCLI -i "$f" -t 1 \ 
    --angle 1 -c 1 -o "/Users/abc/Desktop/TestVidDest/$(basename $f)" \
    -f mp4  -4  -O  --decomb="fast" -w 1280 -l 720 --modulus 16 \
    -e x264 -b 3800 -2  -T  --cfr -a 1 -E faac -6 dpl2 -R 48 -B 128 \
    -D 0 --gain 0 --audio-fallback ffac3 --x264-preset=slow  \
    --x264-profile=high  --x264-tune="film"  --h264-level="4.0" \
    --verbose=1  &
done

The problem is when I manually run this script from Automator it works fine but when new files are added in the folder then this script is called but videos are not converted. If I remove '&' from the end of the command then it works with new files but not in hidden mode and I want it to run in hidden mode.

So if anybody can guide me about what i am doing wrong here???

Log from the console:

Console Log

Best Answer

First, I'm assuming that you accidentally chopped the '/' character off the front of the path to Handbrake in your example. Second, when you say "hidden mode" you mean run in the background.

What happens if you run the command from the command line?

How do you know the command isn't running when you run it in background mode? Are you doing a "ps" command from the command line to see if it is running or not?

Have you tried adding ">>~/HB_log.txt 2>&1" just before the "&" command so that you get a log of both the output and the errors it might be putting out?

If only the first part of the name is being used then I assume that the quote characters around the name are being stripped - try escaping them with a '\'. Like so '\"/Users/abc/Desktop/TestVidDest/$(basename $f)\" ' and see what happens.

I also suspect that problems with the name might be upsetting the entire line and causing your problem.

I would actually write a shell script that you could test externally and then call your shell script from Automator.