Skip to content

Instantly share code, notes, and snippets.

@bbbart
Created August 23, 2022 20:15
Show Gist options
  • Select an option

  • Save bbbart/5c8e52ca1c6f5bb0b1a66b5cc5eba1ae to your computer and use it in GitHub Desktop.

Select an option

Save bbbart/5c8e52ca1c6f5bb0b1a66b5cc5eba1ae to your computer and use it in GitHub Desktop.
#!/usr/bin/env sh
# changes the volume (pipewire)
# indicates the current volume (notify-send)
ICON="/usr/share/icons/Adwaita/scalable/legacy/multimedia-volume-control-symbolic.svg"
function get_volume {
# when unmuted, returns the volume (float)
# when muted, returns zero
volume_output=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
if echo ${volume_output} | grep --quiet MUTED;
then
raw_volume=0
else
raw_volume=$(echo ${volume_output} | cut -d' ' -f2) # 0.00 - 1.53
fi
echo 100 \* ${raw_volume} / 1.53 | bc
}
function notify {
volume=$(get_volume)
node_description=$(wpctl inspect @DEFAULT_AUDIO_SINK@ | grep node.description | cut -d\" -f2)
notify-send --icon="${ICON}" --expire-time=1000 --transient --replace-id=865863 --urgency=low --hint=int:value:${volume} --hint=string:hlcolor:'#fff' "${node_description}"
}
case $1 in
up)
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+
notify
;;
down)
wpctl set-mute @DEFAULT_AUDIO_SINK@ 0
wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-
notify
;;
toggle)
wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
notify
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment