Skip to main content

How to Play a Sound After a Terminal Command Completes

 


Sometimes, while working on the terminal, especially during long-running processes, it’s useful to have an audible notification when the task is finished. In this guide, we’ll show you how to make your terminal play a sound after any command completes, ensuring you're alerted without constantly checking the terminal.


Why Do This?

This trick can save time and improve workflow, especially when:

  • You’re running lengthy build processes or installations.
  • You’re waiting for large file transfers.
  • You're programming embedded systems and need confirmation when flashing is done.

Let’s dive into how to do this on a Linux system.

Step-by-Step Guide to Playing a Sound After a Command


1. Using paplay or aplay to Play Sounds

On most Linux distributions, you can use paplay or aplay to play sound files directly from the terminal. Here's how you can append a sound notification after a command.


Basic Command Structure:

PC:~$ your_command && paplay /path/to/soundfile.oga 

Or, if you're using aplay (for .wav files):

PC:~$ your_command && aplay /path/to/soundfile.wav

  • your_command is any terminal command you wish to execute.
  • && ensures the sound plays only if the command completes successfully. If you want it to play regardless of success or failure, use a semicolon ;.
  • /path/to/soundfile is the location of the sound file you want to play. There are often default system sounds available in /usr/share/sounds/.
  • Making It Even More Generic 

    To make this method even more flexible, you can create a simple alias or function in your .bashrc file that appends sound to any command you run.


    notify_when_done() {

        $1 && paplay /usr/share/sounds/freedesktop/stereo/complete.oga

    }

    Now, you can run:

     notify_when_done "your_command"

    Conclusion 

    Feel free to customize the sound files to your liking and make your terminal experience a little more user-friendly!


    Pro Tip: You can extend this method to use visual notifications as well, like notify-send, for even more robust alerts!

    Comments

    Popular posts from this blog

    Industrial Internet Use-Cases

    The potential for the Industrial Internet is vast with opportunities spread over wide areas of productivity, such as logistics, aviation, transportation, healthcare, energy production, oil and gas production, and manufacturing. As a result, many use-cases will make industry executives wake up and consider the possibilities of the IIoT. After all, industry only requires a minimal shift in productivity to deliver huge revenue, an example is that even an increase of 1% of productivity can produce huge revenue benefits such as aviation fuel savings. In order to realize these potential profits, industry has to adopt and adjust to the Industrial Internet of Things. However, spotting, identifying, and then strategically targeting the opportunities of the IIoT is not quite as easy as it might seem. It is important, therefore, to create use-cases that are appropriate to vertical businesses. For instance, the requirements of manufacturing differ from logistics, which also differs to healthcare....

    Passive Sign Convention

    Whenever the reference direction for the current in an element is in the direction of the reference voltage drop across the element (as in Fig. 1.5 ), use a positive sign in any expression that relates the voltage to the current. Otherwise, use a negative sign. We apply this sign convention in all the analyses that follow. Our purpose for

    Linear regulator current boost circuits

    Voltage Regulator Current Boost Circuits Voltage regulators, such as the LM317, 78xx series, or other linear regulators , are commonly used for providing a stable output voltage. However, these regulators have a maximum current limit , often in the range of 1A to 1.5A for typical ICs. To increase the current handling capability, external pass transistors are added in a current boost configuration. How Current Boost Circuits Work The circuits shown in the image use NPN power transistors ( 2N6133, 2N6124 ) to handle additional current while the regulator maintains voltage regulation. First Circuit (Single NPN Pass Transistor) The voltage regulator drives the base of Q1 (2N6133) . The transistor acts as a current amplifier . R1 limits the base current to Q1, ensuring proper operation. The regulator supplies only a small portion of the total current , while Q1 handles most of the load current . Second Circuit (Darlington Configuration with Current Limit) Uses an additional PN...