summaryrefslogtreecommitdiff
path: root/lower_volume
blob: e2dd254efe37a0e1c618644cd158df7da6e4419a (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash

# Function to get the class name of the focused application
get_focused_app_class() {
    window_id=$(xdotool getactivewindow)
    xdotool getwindowclassname $window_id
}

# Function to get the sink input ID based on the sink input name
get_sink_input_id() {
    sink_input_name="$1"
    pulsemixer --list-sinks | grep -i "$sink_input_name" | awk -F'ID: |, Name:' '{print $2}'
}

# Function to decrease the volume of a sink input
decrease_volume() {
    sink_input_id="$1"
    volume_decrease="$2"
    pulsemixer --id "$sink_input_id" --change-volume -"$volume_decrease"
    echo "Decreased volume of sink input $sink_input_id by $volume_decrease%"
}

# Configuration
volume_decrease_percentage=5

# Get the class name of the focused application
app_class=$(get_focused_app_class)

# Determine the sink input name based on the focused application class
case "$app_class" in
    "qutebrowser"|"St"|"Zathura")
        sink_input_name="Music Player Daemon"
        ;;
     "Mednafen")
     	sink_input_name="mednafen"
	;;
     "mpv")
     	lower_volume_mpv
	;;
    *)
        sink_input_name="$app_class"
        ;;
esac

if [ -n "$sink_input_name" ]; then
    # Get the sink input ID based on the sink input name
    sink_input_id=$(get_sink_input_id "$sink_input_name")

    if [ -n "$sink_input_id" ]; then
        # Decrease the volume of the specified sink input
        decrease_volume "$sink_input_id" "$volume_decrease_percentage"
    else
        echo "Sink input not found for application: $sink_input_name"
    fi
else
    echo "No sink input name specified for application class: $app_class"
fi