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!

Ask a Question

Get help from others!

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