Skip to content

Commit

Permalink
pactl: Work around old pactl by a wrapper script
Browse files Browse the repository at this point in the history
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 streetturtle#390.
  • Loading branch information
Stefan Huber committed Jan 25, 2023
1 parent ef70d16 commit 946729e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pactl-widget/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 30 additions & 0 deletions pactl-widget/pactl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 946729e

Please sign in to comment.