Skip to content

Instantly share code, notes, and snippets.

@pheuberger
Last active June 10, 2024 20:37
Show Gist options
  • Save pheuberger/9f11ace7c3f12eecbe4fd217e17bed83 to your computer and use it in GitHub Desktop.
Save pheuberger/9f11ace7c3f12eecbe4fd217e17bed83 to your computer and use it in GitHub Desktop.
Polybar pipewire configuration
;...
; choose the modules to display
modules-right = pipewire battery wlan
;...
[module/pipewire]
type = custom/script
label = "%output%"
label-font = 1
label-padding = 3
interval = 2.0
exec = ~/.config/polybar/pipewire.sh
click-right = exec pavucontrol &
click-left = ~/.config/polybar/pipewire.sh mute &
scroll-up = ~/.config/polybar/pipewire.sh up &
scroll-down = ~/.config/polybar/pipewire.sh down &
Music blasting:
<NORMAL_SPEAKER_ICON> 12% Built-in Audio
Muted:
<MUTED_SPEAKER_ICON> Built-in Audio
#!/bin/bash
# this file goes into ~/.config/polybar/pipewire.sh
# don't forget to run chmod +x ~/.config/polybar/pipewire.sh
function main() {
SINK=$(wpctl inspect @DEFAULT_AUDIO_SINK@ | sed -n '/node.description/ s/.*node\.description = \"\(.*\)\"$/\1/p')
VOLUME=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed -n "s!^Volume:.* \([[:digit:]]\+\.[[:digit:]]\+\).*!\1!p")
IS_MUTED=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed -n "s!^Volume:.*\(\[MUTED\]\)\$!\1!p")
action=$1
if [ "${action}" == "up" ]; then
wpctl set-volume @DEFAULT_AUDIO_SINK@ 4%+
elif [ "${action}" == "down" ]; then
wpctl set-volume @DEFAULT_AUDIO_SINK@ 4%-
elif [ "${action}" == "mute" ]; then
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
else
if [ "${IS_MUTED}" != "" ]; then
# add a nice muted speaker icon here
echo " ${SINK}"
else
PERCENT_VOL=$(echo "${VOLUME} * 100" | bc)
# add a nice blasting speaker icon here
printf " %.0f%% %s\n" "$PERCENT_VOL" " $SINK"
fi
fi
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment