Send a Notification Badge to the Terminal Dock Icon When a Task is Finished
Not long ago we showed you how to announce when a command line task was finished by using the ‘say’ command, but because it speaks aloud it may be inappropriate to use in a quiet environment. A much more subtle notification takes advantage of Terminal apps new usage of the BEL alert, which in OS X Lion onward pushes a red notification badge to the Dock icon rather than sounding the awful hardware beep.
Adding a notification alert to a completed command is simple, just append “&& tput bel” to the end of a command. For example, to throw the notification alert when the make command is finished running it would look like the following:
make install && tput bel
When finished running, the default system alert will sound, the Terminal dock icon will bounce with a new red notification badge added.
If you want to see it in action in OS X, try it with ping and then go away from the Terminal app:
ping -c 5 www.google.com && tput bel
This can be much better than the “say” alert because it remains useful even when the computer is muted, and it’s more versatile than the Growl notification method since it does not require any additional software to be installed to function. It works in OS X Lion and OS X Mountain Lion.
Thanks to Austin L. for sending this in!
awesome info.. loved it..
tput gave me terminal errors. But this worked:
ping -c 5 google.com ; printf ‘\a’
This is definitive not working on my Mac mini 3,1 with Mac OS 10.6.8. :-(
What errors do you get and what shell are you using?
I just wanted to add a few things. The ‘&&’ means, in most shells, run the next command if and only if the first command was successful (no error on exit). ‘||’ is the opposite: run if exit on error. The way to be notified whether or not an error occurred is use a semicolon ‘;’. Don’t forget to use spaces around those operators and semicolon because some shells are sensitive to that.
Or simply do
$ echo ^V^G
The ‘$’ is the shell’s prompt. ‘^V’ is control-V and ‘^G’ is control-G.
Also agree…doesn’t work in iTerm.
Interesting concept though. Can you also make it bounce as well?
sad is not work in iTerm
Oh, by the way, the escape code for the BEL command is ‘\a’.
>> printf ‘\a’
Is equivalent to this for these purposes:
>> tput bel
Tested it out with a shell script, the numbers go up nice and high. http://f.cl.ly/items/411e2B0E3B2g2l0t1O3M/Screen%20Shot%202012-07-17%20at%2021.27.15.png
This only works if the terminal isnt the frontmost application
So switch out of the terminal to another app and then then you get the red badge
Great trick, I will definitely use this thanks.