From 946729e41958df8bad2eb2dfa56217da81aa47ae Mon Sep 17 00:00:00 2001 From: Stefan Huber Date: Wed, 25 Jan 2023 21:03:07 +0100 Subject: [PATCH] pactl: Work around old pactl by a wrapper script Older versions of pactl, like the one shipped by Debian Bullseye, do not provide the get-* commands, like get-sink-volume or get-sink-mute. Work around them by providing a wrapper script for pactl that provides those commands. Fixes issue #390. --- pactl-widget/README.md | 5 +++++ pactl-widget/pactl | 30 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100755 pactl-widget/pactl diff --git a/pactl-widget/README.md b/pactl-widget/README.md index 24e44710..f7d5ed12 100644 --- a/pactl-widget/README.md +++ b/pactl-widget/README.md @@ -26,6 +26,11 @@ s.mytasklist, -- Middle widget }, ``` +**Note.** Older versions of `pactl`, like the one shipped with Debian Bullseye, +do not provide commands like get-sink-volume or get-sink-mute, which are used +by this widget. However, a wrapper script `pactl` is provided that augments +`/usr/bin/pactl` to provide these commands. + ### Shortcuts To improve responsiveness of the widget when volume level is changed by a shortcut use corresponding methods of the widget: diff --git a/pactl-widget/pactl b/pactl-widget/pactl new file mode 100755 index 00000000..2e312632 --- /dev/null +++ b/pactl-widget/pactl @@ -0,0 +1,30 @@ +#!/bin/sh + +PACTL=/usr/bin/pactl + +if [ "$1" = "--help" ]; then + echo "This is wrapper script around ${PACTL} to provide the commands get-sink-volume" + echo "and get-sink-mute if not provided by pactl." + echo "" + ${PACTL} "${@}" +fi + +# pactl already provides the get-* commands, so plainly call pactl +if [ -n "$(${PACTL} --help | grep get-)" ]; then + $PACTL "${@}" +fi + +CMD=$1 +DEVICE=$2 + +if [ "${DEVICE}" = "@DEFAULT_SINK@" ]; then + DEVICE=$(pactl info | grep "Default Sink:" | sed "s/.*: *//") +fi + +if [ "${CMD}" = "get-sink-volume" ]; then + pactl list sinks | grep -E "(Sink #|Name:|^\s*Volume:)" | grep -A2 ${DEVICE} | grep "Volume:" | sed "s/^\s*//" +fi + +if [ "${CMD}" = "get-sink-mute" ]; then + pactl list sinks | grep -E "(Sink #|Name:|Mute:)" | grep -A2 ${DEVICE} | grep "Mute:" | sed "s/^\s*//" +fi