Hi there, new Bazzite user here, with Gnome, on a desktop.
I’m bit new to Linux and trying to familiarize myself with bash scripting and terminal usage.
Here is my situation i connected the headphone port of my nintendo switch to the rear line-in of my PC and set a loopback with pipewire, so that the sound of my console passthrough my pc to my audio setup.
So far I managed to make a script to start the loopback using pw-loopback.
It works as expected, but if i want to stop it, the only way i have found is to launch pavu and click on terminate playback from there.
Is there a command i could use to stop it from a script ?
Better yet is there a way to make a script check if pw-loopback is already running then terminate it, if not launch it. That way i could toggle the sound on/off from a single script.
#!/bin/bash
PW_LOOPBACK_PID_FILE="/var/run/pw-loopback.pid"
if [ -f "$PW_LOOPBACK_PID_FILE" ]; then
PW_LOOPBACK_PID=$(cat "$PW_LOOPBACK_PID_FILE")
if kill -0 "$PW_LOOPBACK_PID" > /dev/null 2>&1; then
# pw-loopback is running, kill it
kill "$PW_LOOPBACK_PID"
else
# pw-loopback is not running, remove stale pid file
rm "$PW_LOOPBACK_PID_FILE"
fi
else
# pw-loopback is not running, start it
pw-loopback &
PW_LOOPBACK_PID=$!
echo "$PW_LOOPBACK_PID" > "$PW_LOOPBACK_PID_FILE"
fi
#!/bin/bash
PW_LOOPBACK_PID=$(pgrep pw-loopback)
if [ -n "$PW_LOOPBACK_PID" ]; then
kill -9 $PW_LOOPBACK_PID
else
/usr/bin/pw-loopback & # Start pw-loopback in the background
fi
Thank you ! Your script does allow me to kill the loopback but it would not start one if non existed.
I change your script to
#!/bin/bash
PW_LOOPBACK_PID=$(pgrep pw-loopback)
if [ -n "$PW_LOOPBACK_PID" ]; then
kill -9 $PW_LOOPBACK_PID
else
pw-loopback # Start pw-loopback in the background,
fi