aboutsummaryrefslogtreecommitdiff
path: root/sway-de/wob/.local/bin/setvol
blob: f8bb4dfb4a0697bd2c31cf682eaa143a14e1982b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash

set -euo pipefail

wobsock="$XDG_RUNTIME_DIR/wob.sock"
if [ ! -p "$wobsock" ]; then
  echo $wobsock
  echo "communication socket not found"
  exit 2
fi

current_volume=$(pactl get-sink-volume @DEFAULT_SINK@ | grep Volume | sed -e 's/.* \([0-9][0-9]*\)%.*/\1/')
case $1 in
    up)
        increment=$(( 5 - ( current_volume % 5 ) ))
        newvol=$(( current_volume + increment ))
        if [ $newvol -gt 100 ]; then
            newvol=100
        fi
        pactl set-sink-volume @DEFAULT_SINK@ $newvol%
        echo $newvol > $wobsock;;
    down)
        increment=$(( ( ( current_volume - 1 ) % 5 ) + 1 ))
        newvol=$(( current_volume - increment ))
        if [ $newvol -lt 0 ]; then
            newvol=0
        fi
        pactl set-sink-volume @DEFAULT_SINK@ $newvol%
        echo $newvol > $wobsock;;
esac