From 8ff5dec689c3f4577960c25e284add5a5e9a9fcf Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Mon, 10 Jan 2022 14:07:32 -0700 Subject: Change set-sink.sh Before this script would use the PID of the current window to infer the input to switch. However some frontends use a daemon to output the sound, so it doesn't work in that case. Instead, now, set-sink will prompt the user to select the active sink to switch. If there is only one active sink it will automatically move that one. --- extras/HOME/.local/bin/set-sink.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/extras/HOME/.local/bin/set-sink.sh b/extras/HOME/.local/bin/set-sink.sh index be04833..aa0b91c 100755 --- a/extras/HOME/.local/bin/set-sink.sh +++ b/extras/HOME/.local/bin/set-sink.sh @@ -1,7 +1,6 @@ #!/bin/bash -current_pid=$(xdotool getactivewindow getwindowpid) -DMENU=(dmenu -i -nf "#88ff88" -sb "#88ff88" -p "Move Audio" -l 12 -dim 0.4) +DMENU=(dmenu -i -nf "#88ff88" -sb "#88ff88" -p "Move Audio To" -l 12 -dim 0.4) sinks="$( pactl list sinks | while read line ; do @@ -19,27 +18,34 @@ sinks="$( client_input="$( pactl list sink-inputs | while read line ; do case "$line" in - application.process.id\ =*) + application.name\ =*) app="${line//*= \"}" app="${app%%\"}" + echo "$app: $media "'#'"$obj" ;; - object.id\ =*) - obj="${line//*= \"}" - obj="${obj%%\"}" - echo "$obj $app" + media.name\ =*) + media="${line//*= \"}" + media="${media%%\"}" + ;; + Sink\ Input\ \#*) + obj="${line//*#}" ;; esac done )" -input_sink=$(echo "$client_input" | grep "$current_pid\$") -input_sink=${input_sink%% *} +echo "Client Input: $client_input" + +if [[ "$(wc -l <<< "$client_input")" -gt 1 ]] ; then + client_input="$("${DMENU[@]}" -p "Move Audio From" <<< "$client_input")" +fi + +input_sink=${client_input//*#} -selected_sink=$(echo "$sinks" | "${DMENU[@]}") +selected_sink=$("${DMENU[@]}" <<< "$sinks") sink_num=${selected_sink//*#} -#echo "$sinks" -#echo "$client_input" +echo "Sinks: $sinks" echo "pactl move-sink-input $input_sink $sink_num" pactl move-sink-input "$input_sink" "$sink_num" -- cgit