Send a Notification Badge to the Terminal Dock Icon When a Task is Finished

Jul 17, 2012 - 12 Comments

A notification badge alert is sent to the Terminal icon in the OS X Dock

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!

.

Related articles:

Posted by: William Pearson in Command Line, Mac OS, Tips & Tricks

12 Comments

» Comments RSS Feed

  1. Mikee says:

    awesome info.. loved it..

  2. MV says:

    tput gave me terminal errors. But this worked:

    ping -c 5 google.com ; printf ‘\a’

  3. cpX says:

    This is definitive not working on my Mac mini 3,1 with Mac OS 10.6.8. :-(

  4. Derek says:

    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.

  5. LL Herb J says:

    Or simply do

    $ echo ^V^G

    The ‘$’ is the shell’s prompt. ‘^V’ is control-V and ‘^G’ is control-G.

  6. Also agree…doesn’t work in iTerm.

    Interesting concept though. Can you also make it bounce as well?

  7. adam says:

    sad is not work in iTerm

  8. Austin Lucas says:

    Oh, by the way, the escape code for the BEL command is ‘\a’.

    This command:
    >> printf ‘\a’

    Is equivalent to this for these purposes:
    >> tput bel

  9. Broojo says:

    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

  10. Napoleon Wilson says:

    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

  11. Yosi says:

    Great trick, I will definitely use this thanks.

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site