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

    How to program 8051 based MCU using Ptroteous Schematic capture and Source code editor to use timers using AT892051 + project files

     This tutorial is dedicated to use a 8051 based Microcontroller core and program it using keil's C51 tools on the Proteus Source code editor.  1- Brief History of 8051 one of the first microprocessors 4004 was invented by Intel Corporation as well as  8085 and 8086 microprocessors back in 1981,shortly after Intel introduced an 8-bit microcontroller called the 8051 . It was referred to as system on a chip because it had 128 bytes of RAM, 4K byte of on-chip ROM, two timers, one serial port, and 4 ports (8-bit wide), all on a single chip. When it became so widespread, Intel allowed other manufacturers to make and market different flavors of 8051 with its code compatible with 8051. It means that if you write your program for one flavor of 8051, it will run on other flavors too, regardless of the manufacturer. This has led to several versions with different speeds and amounts of on-chip RAM. 2- Features of AT892051 Microcontroller Compatible with MCS®-51Products 2K ...

    What is the ESP32 VSPI / HSPI

     The ESP32 integrates four SPI peripherals. SPI0 and SPI1 are used to access the ESP32’s attached flash memory and thus are currently not open to users to be used . They share one signal bus via an arbiter. SPI2 and SPI3 are general purpose SPI controllers, sometimes referred to as HSPI and VSPI, respectively. They are open for use. SPI2 and SPI3 have independent signal buses with the same respective names. Each bus has three CS lines to drive up to three SPI slaves.  

    Current Limiter Example Circuits and explained

    The post explains 2 simple universal current controller circuits which can be used for safely operating any desired high watt LED. The universal high watt LED current limiter circuit explained here can be integrated with any crude DC supply source for getting an outstanding over current protection for the connected high watt LEDs.  Why Current Limiting is Crucial for LEDs We know that LEDs are highly efficient devices which are able to produce dazzling illuminations at relatively lower consumption, however these devices are highly vulnerable especially to heat and current which are complementary parameters and affect an LED performance. Especially with high watt LEds which tend to generate considerable heat, the above parameters become crucial issues. If an LED is driven with higher current it will tend to get hot beyond tolerance and get destroyed, while conversely if the heat dissipation is not controlled the LED will start drawing more current until it gets destroyed. In ...