volume

Print audio volume levels and draw sxalert OSD
git clone git://mcdim.xyz/volume.git
Log | Files | Refs | README

commit 4b8859472b15d9f11a577c0918b794ef0c8552ec
Author: Michail Konstantinos Dimopoulos <mk@mcdim.xyz>
Date:   Thu, 15 Oct 2026 18:02:30 +0300

Initial commit

Diffstat:
AREADME.txt | 37+++++++++++++++++++++++++++++++++++++
Avolume.sh | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/README.txt b/README.txt @@ -0,0 +1,37 @@ +volume.sh +========= + +Shell script that outputs your current volume level to stdout for i3blocks +and uses sxalert as a dumb OSD to display it. + +In /etc/i3blocks.conf: + + [volume] + command=~/.scripts/volume #path to script + label=V #label + interval=once + signal=10 + +In ~/.config/sxh + + XF86Audio{Raise,Lower}Volume + pactl set-sink-volume @DEFAULT_SINK@ {+10%, -10%} \ + && pkill -SIGRTMIN+10 i3blocks + + alt + XF86Audio{Raise,Lower}Volume + pactl set-sink-volume @DEFAULT_SINK@ {+1%, -1%} \ + && pkill -SIGRTMIN+10 i3blocks + + XF86AudioMute + pactl set-sink-mute @DEFAULT_SINK@ toggle \ + && pkill -SIGRTMIN+10 i3blocks + + +This way, input from your volume keys sends a SIG 10 to i3blocks, and it +redraws the audio on the status bar, along with displaying the alert. + +notes +----- + +sxalert processes are killed and dedrawn. Thus, this is not the most smooth +OSD, as the Xwindow flickers between redraws. It works fine, however. diff --git a/volume.sh b/volume.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +mute=$(pactl get-sink-mute @DEFAULT_SINK@ | cut -d" " -f2) +str="yes" + +pidfile="${XDG_RUNTIME_DIR:-/tmp}/sxalert-volume.pid" + +if [ -f "$pidfile" ]; then + kill "$(cat "$pidfile")" 2>/dev/null +fi + +if [ "$mute" = "$str" ]; +then + echo "Muted" + sxalert " " " Muted" " " -d 730 -g 0 -r ffffff \ + -t ffffff </dev/null >/dev/null 2>&1 & + echo $! > "$pidfile" +else + audio=$(pactl get-sink-volume @DEFAULT_SINK@ | tr -s ' ' \ + | cut -d" " -f5) + echo $audio + + $audioint=$(echo -n $audio | cut -d"%" -f1) + + let bar=$audio/100*8 + bar=$(awk -v audio="$audio" 'BEGIN { print audio / 100 * 8 }') + bar=${bar%%.*} + + if [ $bar -eq 0 ]; then + visbar=" " + elif [ $bar -eq 1 ]; then + visbar="▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁" + elif [ $bar -eq 2 ]; then + visbar="▁▁▁ ▂▂▂ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁" + elif [ $bar -eq 3 ]; then + visbar="▁▁▁ ▂▂▂ ▃▃▃ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁" + elif [ $bar -eq 4 ]; then + visbar="▁▁▁ ▂▂▂ ▃▃▃ ▄▄▄ ▁▁▁ ▁▁▁ ▁▁▁ ▁▁▁" + elif [ $bar -eq 5 ]; then + visbar="▁▁▁ ▂▂▂ ▃▃▃ ▄▄▄ ▅▅▅ ▁▁▁ ▁▁▁ ▁▁▁" + elif [ $bar -eq 6 ]; then + visbar="▁▁▁ ▂▂▂ ▃▃▃ ▄▄▄ ▅▅▅ ▆▆▆ ▁▁▁ ▁▁▁" + elif [ $bar -eq 7 ]; then + visbar="▁▁▁ ▂▂▂ ▃▃▃ ▄▄▄ ▅▅▅ ▆▆▆ ▇▇▇ ▁▁▁" + elif [ $bar -ge 8 ]; then + visbar="▁▁▁ ▂▂▂ ▃▃▃ ▄▄▄ ▅▅▅ ▆▆▆ ▇▇▇ ███" + fi + + sxalert " " " $audio $visbar" " " -d 730 -g 0 -r ffffff \ + -t ffffff </dev/null >/dev/null 2>&1 & + echo $! > "$pidfile" +fi