From b3474e85dcce03e7de0b4a4e30ff7fad1f38ee26 Mon Sep 17 00:00:00 2001 From: ryukamish Date: Sat, 11 Apr 2026 18:25:38 +0530 Subject: add: small bash scripts for added functionality --- scripts/switch-audio | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/switch-audio (limited to 'scripts/switch-audio') diff --git a/scripts/switch-audio b/scripts/switch-audio new file mode 100755 index 0000000..8b45090 --- /dev/null +++ b/scripts/switch-audio @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +focused_monitor="$(hyprctl monitors -j | jq -r '.[] | select(.focused == true).name')" + +sinks=$(pactl -f json list sinks | jq '[.[] | select((.ports | length == 0) or ([.ports[]? | .availability != "not available"] | any))]') +sinks_count=$(echo "$sinks" | jq '. | length') + +if [ "$sinks_count" -eq 0 ]; then + notify-send -u normal "$focused_monitor" "No audio devices found" + exit 1 +fi + +current_sink_name=$(pactl get-default-sink) +current_sink_index=$(echo "$sinks" | jq -r --arg name "$current_sink_name" 'map(.name) | index($name)') + +if [ "$current_sink_index" != "null" ]; then + next_sink_index=$(((current_sink_index + 1) % sinks_count)) +else + next_sink_index=0 +fi + +next_sink=$(echo "$sinks" | jq -r ".[$next_sink_index]") +next_sink_name=$(echo "$next_sink" | jq -r '.name') + +next_sink_description=$(echo "$next_sink" | jq -r '.description') +if [ "$next_sink_description" = "(null)" ] || [ "$next_sink_description" = "null" ] || [ -z "$next_sink_description" ]; then + sink_id=$(echo "$next_sink" | jq -r '.properties."object.id"') + next_sink_description=$(wpctl status | grep -E "\s+\*?\s+${sink_id}\." | sed -E 's/^.*[0-9]+\.\s+//' | sed -E 's/\s+\[.*$//') +fi + +if [ "$next_sink_name" != "$current_sink_name" ]; then + pactl set-default-sink "$next_sink_name" +fi + +notify-send -u low "Audio: $focused_monitor" "Switching to $next_sink_description" -- cgit v1.3