Linux - Audio notification after long running command has finished

The following small trick was too simple for a post in my eyes, but too helpful in the past for not sharing. From time to time a I have a long running command in my development process, that can be compiling, evaluating data or something else that takes longer than 5 minutes. In the most cases I will focus on something else in that time and check pretty late that the command has already finished. A simple solution for me is to play some audio signal after the command has finished.

The idea is pretty simple and works also on other operating systems with other music playing commands. I just append a command that plays a audio track after the long runnign command.

Play music from the command line in Linux

I have choosen the command play from the package sox in Debian based systems. The package can be installed with super user permissions by the following command.

apt-get install sox

A audio file can be played with the following command.

play 02.\ Jane\ Became\ Insane.ogg

02. Jane Became Insane.ogg:

 File Size: 2.97M     Bit Rate: 144k
  Encoding: Vorbis
  Channels: 2 @ 16-bit   Track: 2 of 11
Samplerate: 44100Hz      Album: .limbo messiah
Replaygain: off         Artist: Beatsteaks
  Duration: 00:02:45.04  Title: Jane Became Insane

In:100%  00:02:45.04 [00:00:00.00] Out:7.28M [      |      ]        Clip:0
Done.

Run music after long running command

Let us assume that sleep 5 represents our long running command. We just need to append the play command and we will be reminded with audio after the long running command has finished.

sleep 5; play 02.\ Jane\ Became\ Insane.ogg

Create audio reminder command

This idea can get more and more comfortable. Here just as example a bash script that takes every command and appends the play command afterwards.

#!/bin/bash

$*; play -q /usr/share/sounds/gnome/default/alerts/drip.ogg

We can place this script as file arem for audio reminder as executable in /usr/local/bin/ for example and can provided this as pre command for every long running command.

arem sleep 5
Next Previous