summaryrefslogtreecommitdiff
path: root/scripts/switch-audio
diff options
context:
space:
mode:
authorryukamish <[email protected]>2026-04-11 18:25:38 +0530
committerryukamish <[email protected]>2026-04-11 18:25:38 +0530
commitb3474e85dcce03e7de0b4a4e30ff7fad1f38ee26 (patch)
treebcfe42ad76a825c283eec653140ab4052f0b3017 /scripts/switch-audio
parent607891801fbf2051a0c9062d15a445dd238c1e1b (diff)
add: small bash scripts for added functionality
Diffstat (limited to 'scripts/switch-audio')
-rwxr-xr-xscripts/switch-audio35
1 files changed, 35 insertions, 0 deletions
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"