Elementary OS terminal bell in UBUNTU

Ask Ubuntu Asked by Abhay Patil on September 20, 2020

I recently shifted from Elementary OS to UBUNTU 20.04 LTS. One very useful feature on Elementary OS was the terminal bell. When a command in terminal is done executing, there is a bell ring sound and a notification in the notification area.

This can be achieved by using notify-send "Task Complete" && printf 'a' along with the original command by using &&.

But here is the catch:
1. This command is very long and needs to be typed every time. alias can be used but still you have to type it every time.
2. It rings this even when the terminal is in focus.

So my question is, I want a specific command to execute every time which is notify-send "Task Complete" && printf 'a' only when terminal is out of focus. And that too without typing this every time.

Some people suggested How to make a sound once a process is complete?
But my question was to ring the bell without typing any extra command. Is there a way I could integrate some script or something in the terminal itself, so that it calls the beep sound on its own without any extra commands.

One Answer

Interesting question!

I've come up with my own concoction using xdotool (sudo apt-get install xdotool) and pstree (sudo apt-get install psmisc).

#! /bin/bash
ACTIVE_WINDOW_PID=$(xdotool getactivewindow getwindowpid)
if [ ! $(pstree -spA $PPID | grep "(${ACTIVE_WINDOW_PID})") ]; then
  notify-send "Task Complete" && printf 'a'

I have this in ~/bin/ring and I used the following command to verify if it works: sleep 3 ; ~/bin/ring.

Using xdotool you could even get the window title and report it using notify-send, or focus the terminal window when the command exists.

Answered by Jurrie on September 20, 2020

Add your own answers!

Related Questions

Firewall won’t work on Ubuntu

1  Asked on December 29, 2021 by jack94


Upgrade from 18.04 to 20.04 but retain specific kernel (4.9)

0  Asked on December 29, 2021 by walter-zambotti


Installing system on file?

0  Asked on December 29, 2021 by ctm-8400


Why is my browser leaving out so much space in both sides?

8  Asked on December 29, 2021 by moshrekul-islam


Log files fill up too fast

0  Asked on December 29, 2021 by hardik-katehara


Can’t see Wi-Fi settings in Ubuntu 20.04 LTS

2  Asked on December 27, 2021 by nova1323


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP