Batch Encoding Videos HandBrake CLI & growlnotify (Mac OS X)

Posted On

2013 Oct 19

over 10 years ago

Updated On

2023 Jan 01

over 1 year ago

I ran into a slight problem where growlnotify command was not found while running a Shell Script in Automator. Took me sometime to find out the problem which was actually quite easy (if I had a lil bit more experience with unix)

Noob with Unix commands and all, thought I will write a short tutorial and solutions to the average user with none or little experience with unix commands in Mac

I can't cover all topics in a single post, it would result in a tutorial for using Growl Notifications , HandBrake CLI and Automator

Anyone with some experience will understand what is going on, and I will try to describe with some detail on their actions

  • My system
    • Mac OS X 10.7.5 (Solution updated to support 10.11)
    • Growl 2.1.2 (App Store)
    • GrowlNotify 2.1
    • HandBrake CLI 0.9.9

Case - Batch Encoding Videos with HandBrake CLI (Service)


A service I created some time ago, which batch encode videos which I have shot into a lower quality video file (mp4) using HandBrake CLI (a command line version of video converting tool HandBrake) for backup. It also labels the selected files as Grey (I can filter out the labelled items and delete them). A general useful service, you can also encode other video formats like avi, mkv etc into mp4

for if in "$@"
	/Applications/HandBrakeCLI -i "$if" -o "$if".mp4 --preset="Normal"

The code for standard encoding. Encodes current selected file(s) and output to same folder with .mp4 extension

> HandBrake-log.txt outputs encoding process into a text file, which is then read by GeekTool onto my Desktop

Adding notifications using Growl

Encoding videos is a time consuming process and I thought it would be really nice if I could use a Growl notification to notify that the video encoding has been finished or which file it is actually encoding currently

Problem: growlnotify command not found (error 127)

Installed GrowlNotify 2.1 (under General downloads of site) and tried running the command in Terminal and Growl works, but when I put in the code with HandBrake shell script, a command not found error occurred

Solution (Updated! 10.11 El Capitan)

After updating to El Capitan, copying growlnotify to /usr/bin no longer work as Terminal will return the following:
Operation not permitted

Newest solution here: Update the automator code to call the growlnotify directly! (Weird I didn't think about this before)

for if in "$@"
	/usr/local/bin/growlnotify -a "HandBrake" -m "Encoding ${if##\*/}" "HandBrake Encode - Normal"
	/Applications/HandBrakeCLI -i "$if" -o "$if".mp4 --preset="Normal" > HandBrake-log.txt
	/usr/local/bin/growlnotify -s -a "HandBrake" -m "Encoding Done" "${if##\*/}"

Solution Notes: (Before 10.11)

It appears that my growlnotify command is installed in a different location other than /usr/bin , and running the shell script in Automator will result in not being able to find the command

Knowing your $PATH in Automator & finding growlnotify

Explaining on what $PATH is, is beyond the scope of this post. Summary, $PATH is a variable in Unix, and in this case, tells Automator where to look for commands. If your growlnotify is not in the list of folders provided in $PATH, it will not be able to find your growlnotify command, thus the command not found error. Simple

So what/where is the $PATH in Automator?

Run a simple echo $PATH and you see the results in Automator. Now we know that Automator is looking for the growlnotify command in /usr/bin:/bin:/usr/sbin:/sbin

That looks complicated?! " : " the colon is used to separate folders. Just means $PATH consists of folder /usr/bin & /bin & /usr/sbin & /sbin

So where is my growlnotify ?! Go back to Terminal, type in:

which growlnotify

My growlnotify is installed in /usr/local/bin/, now we know where our growlnotify is located, and why the command was not found, obviously, its in a different place. Your growlnotify might be installed in a different location

Why running growlnotify in Terminal works

As we do an echo $PATH in Terminal, my $PATH consists of /usr/local/bin, which is where growlnotify is located, so it works. This varies, your $PATH might be different with mine, but it doesn't matter

Not sure on this, as I said, not a unix veteran, so this might actually be the default location whenever a new command is installed


My Solution

Copy the growlnotify command into /usr/bin

To do that you can use the following command:

sudo cp /usr/local/bin/growlnotify /usr/bin/growlnotify

Please replace the code above with your own growlnotify directory. Your growlnotify location might be different to mine

After you have run the command, you can double check again by running which growlnotify in Terminal to see where it is located. It should show /usr/bin/growlnotify. Now go back to Automator, run a test shell script, and it should work

Updated Shell Script

for if in "$@"
	growlnotify -a "HandBrake" -m "Encoding ${if##\*/}" "HandBrake Encode - Normal"
	/Applications/HandBrakeCLI -i "$if" -o "$if".mp4 --preset="Normal" > HandBrake-log.txt
	growlnotify -s -a "HandBrake" -m "Encoding Done" "${if##\*/}"

Note - Pass input: as arguments


growlnotify -a "HandBrake" -m "Encoding ${if##\*/}" "HandBrake Encode - Normal"

growlnotify -s -a "HandBrake" -m "Encoding Done" "${if##\*/}"

Adding a -s will sticky the Growl notification

The code without output to text file

for if in "$@"
	growlnotify -a "HandBrake" -m "Encoding ${if##\*/}" "HandBrake Encode - Normal"
	/Applications/HandBrakeCLI -i "$if" -o "$if".mp4 --preset="Normal"
	growlnotify -s -a "HandBrake" -m "Encoding Done" "${if##\*/}"

Phew! A little nice addition to a useful shell script. There are other and even better code out there which includes better file manipulation, but it is out of the scope of this post

Thank you for reading and please feel free to use this shell script sample in your Automator actions

Copyright © 2012 - 2024 Jason Loong and
Logo by itsjanelia
Excerpts and links may be used, provided that full and clear credit is given to Jason Loong and with appropriate and specific direction to the original content. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited.