0

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.

EDIT 1 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.

2

2 Answers 2

1

I found a satisfactory solution. It uses oh-my-zsh. There is a plugin called bg-notify which does exactly what the question asked for. It even sends a notification in the notification bar, along with an audio cue.

0

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'
fi

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .