Build notifications in Ubuntu

Published on 2015-03-29
Tagged: linux productivity

It's easy to get distracted when you're working on a project with long build times. When I worked on V8, it took about seven minutes to build on my desktop. My current project takes a little over five minutes. This is too long to just wait for it to finish, but not long enough to switch to doing something else productive. It's exactly the right amount of time to get distracted with Hacker News or Reddit though.

I found a tool in Ubuntu that helps me get focused again as soon as the build finishes. notify-send is a command line tool that posts a custom notification on your desktop.

$ notify-send -i weather-clear 'Success!' 'Back to work!'

I use this as part of a small Bash function that I run after a build (in the same command).

function build-notify {
  if [ $? -eq 0 ]; then
    notify-send -i weather-clear 'Success!' 'Back to work!'
    notify-send -i weather-showers 'Failed!' 'What happened?'

The Bash special variable $? is the return code of the most recent command, so it will be 0 after a successful build and non-zero after a failure.

$ make -j8; build-notify

OS X doesn't have this command, but you can post notifications from the command line using AppleScript instead.

$ osascript 'display notification "Back to work!" \ 
             with title "Success!"'

I couldn't find any built-in way to do this in Windows, but there are other tools you can install that accomplish the same thing.

I hope this helps you spend less time on Reddit!