From 3440a583a0cf60ffa4f6a7771bb47d8f5671893d Mon Sep 17 00:00:00 2001 From: Thierry Schork Date: Fri, 11 Jul 2025 06:12:32 +0200 Subject: [PATCH] added cycle_pactl.sh (cherry picked from commit 113c31566b6d21174e48c71fb98026d88c2a76eb) --- bin/cycle_pactl.sh | 17 +++++++++++++++ bin/cycle_sinks.py | 54 ---------------------------------------------- 2 files changed, 17 insertions(+), 54 deletions(-) create mode 100755 bin/cycle_pactl.sh delete mode 100755 bin/cycle_sinks.py diff --git a/bin/cycle_pactl.sh b/bin/cycle_pactl.sh new file mode 100755 index 0000000..40b1ae6 --- /dev/null +++ b/bin/cycle_pactl.sh @@ -0,0 +1,17 @@ +#!/bin/bash +set -e + +default_sink=$(pactl info | grep "Default Sink:" | cut '-d ' -f3) +sinks=$(pactl list short sinks | cut -f2) + +# for wrap-around +sinks="$sinks +$sinks" + +next_sink=$(echo "$sinks" | awk "/$default_sink/{getline x;print x;exit;}") + +pactl set-default-sink "$next_sink" +pactl list short sink-inputs | \ + cut -f1 | \ + xargs -I{} pactl move-sink-input {} "$next_sink" + diff --git a/bin/cycle_sinks.py b/bin/cycle_sinks.py deleted file mode 100755 index 4bd94c5..0000000 --- a/bin/cycle_sinks.py +++ /dev/null @@ -1,54 +0,0 @@ -import pulsectl - -pulse = pulsectl.Pulse('my-client-name') - - -class my_sink: - name = "Here goes the name of the sink" - index = -1 - desc = "Here goes a description" - sink = "" - - def __init__(self, sink): - self.name = sink.name - self.index = sink.index - self.desc = sink.description - self.sink = sink - - def __str__(self): - return f"\"{self.name}\" with index {self.index} and description: \"{self.desc}\"" - - -def get_sinks(): - output_sinks = [] - print(pulse.sink_list()) - for s in pulse.sink_list(): - m = my_sink(s) - output_sinks.append(m) - - print(output_sinks) - return output_sinks - - -def next_sink(output_sinks): - current_sink = pulse.server_info().default_sink_name - position = 0 - for s in output_sinks: - if s.name == current_sink: - break - else: - position += 1 - - if position == len(output_sinks) - 1: - new_output = output_sinks[0] - else: - new_output = output_sinks[position+1] - - print(current_sink + " will be switched to " + new_output.name) - - pulse.default_set(new_output.sink) - - -# Press the green button in the gutter to run the script. -if __name__ == '__main__': - next_sink(get_sinks())