#!/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