Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for terminal bell as a notification #115

Open
mozzwald opened this issue Jul 14, 2016 · 5 comments
Open

Support for terminal bell as a notification #115

mozzwald opened this issue Jul 14, 2016 · 5 comments

Comments

@mozzwald
Copy link

The terminal bell works when the app is running in the foreground with the screen on but after screen turns off or the app is running in the background it no longer plays a sound or vibrates based on the bell-character setting in termux.properties.

This option is useful for being notified of events if connected to another machine via ssh (where termux-notification will not work). Please add support for terminal bell as a notification.

@mozzwald
Copy link
Author

mozzwald commented Aug 10, 2016

As a work around I'm using tmux v2.2 to handle the terminal bell in termux with the following:

apt install tmux play-audio

usr/etc/profile.d/tmux.sh

if [ $TMUX ] ; then
        tmux set-hook -g alert-bell 'run "notif.sh ; return 0"'
fi

usr/bin/notif.sh

#!/data/data/com.termux/files/usr/bin/sh
# enable terminal bell via tmux

if [ ! $SSH_CONNECTION ]; then # Do not notify if attached via ssh
     termux-notification -i 4848 -t "Termux Terminal Bell" -c "Termux Terminal Bell Notification" &
     play-audio -s notification /system/media/audio/notifications/Xenon.ogg &
     termux-vibrate -d 150 &
fi

The profile script is another workaround for tmux 2.2 that will be fixed in 2.3 (already fixed in tmux master branch). In tmux v2.3, the profile script will not be needed and the set-hook option can be added directly to your tmux.conf file. The notif.sh script can be modified to your liking and is run whenever there is a terminal bell.

Update: added ssh check

@twaik
Copy link
Member

twaik commented Dec 23, 2023

Is this still relevant? I can not make system play system bell sound on both Termux and Konsole (I tried echo -en '\a', echo ^G, tput bel, nothing works).

@TomJo2000
Copy link
Member

TomJo2000 commented Dec 23, 2023

Is this still relevant? I can not make system play system bell sound on both Termux and Konsole (I tried echo -en '\a', echo ^G, tput bel, nothing works).

@twaik
printf '\a', echo -en '\a' and tput bel output a BEL control character to the terminal.
echo ^G does not, the GNU Bash or POSIX version of echo does not interpret caret notation.

A BEL char being printed to the terminal causes Termux to send a short vibration to Android on my Device (Android 10), check if you have vibration enabled in the Android quick settings.

@twaik
Copy link
Member

twaik commented Dec 23, 2023

A BEL char being printed to the terminal causes Termux to send a short vibration to Android on my Device (Android 10), check if you have vibration enabled in the Android quick settings.

You are right. I succeed making constantly vibrating phone with while :; do tput bel; done.
But it stops vibrating while screen is locked or application is not on screen. Interesting thing: device keeps vibrating if I keep termux's window (in freeform mode) opened but focusing some other window.

@TomJo2000
Copy link
Member

TomJo2000 commented Dec 23, 2023

There is actually a dedicated escape sequence for notifications,
it's a urxvt escape sequence extension, OSC 777.
i.e \e]777;notify;<title>;<body>\e\\

I don't think Termux implements it.
But it is implemented by: urxvt(obviously), foot and GNOME terminal/libvte(which a lot of terminals use as a base)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants