-
-
Save Ghostbird/6f810a03f7c07dae7b2389082accf6ed to your computer and use it in GitHub Desktop.
#!/bin/bash | |
sources=(telegram zoom teams discord extra) | |
sinks=(telegram kodi zoom teams discord extra) | |
startTime=$(date +%s) | |
function capitalise() { | |
echo $1 | sed -e "s/\b\(.\)/\u\1/g" | |
} | |
function start() { | |
for sink in "${sinks[@]}" | |
do | |
# echo $(capitalise ${sink}) Sink | |
pactl load-module module-jack-sink client_name="'$(capitalise ${sink})'" sink_name="${sink}" sink_properties="starttime=$startTime" connect=no > /dev/null | |
done | |
for source in "${sources[@]}" | |
do | |
# echo $(capitalise ${source}) Source | |
pactl load-module module-jack-source client_name="'$(capitalise ${source}) '" source_name="${source}" source_properties="starttime=$startTime" connect=no > /dev/null | |
done | |
echo "Added extra PulseAudio connections" | |
} | |
function stop() { | |
pactl list modules short | grep $startTime | cut -f1 | xargs -n 1 pactl unload-module | |
echo "Removed extra PulseAudio connections" | |
} | |
# Kill sleep on any of these signals | |
trap '[[ $pid ]] && kill $pid' TERM INT HUP QUIT | |
start | |
sleep infinity & # Run infinite sleep in background | |
pid=$! # Save PID of sleep program | |
wait $pid # Wait for sleep to be killed by the trap | |
stop |
Updated to properly name sinks and sources in pulse and to nicely name them in jack. It turned out that the trick is to send a string wrapped in quotes to jack, if you want to have spaces in the client_name.
Since source and sink are distinct clients in jack, you can't give them the same client_name. However, you can end the name with a space character, so they read the same in a jack connection GUI.
I ran into an issue where I'd get a lot of Failure: Module initialization failed
lines when trying to run the script.
In sudo journalctl -f
I saw that this was because pulseaudio
was hitting the maximum number of files that it was allowed to keep open.
The solution was:
sudo nano /usr/lib/systemd/user/pulseaudio.service
In the section [Service]
add al line that says:
LimitNOFILE=1024
Note: You can use a higher number than 1024 files if necessary.
Afterwards reload the file and restart pulseaudio:
systemctl --user daemon-reload
systemctl --user restart pulseaudio.service
DON'T run these commands with sudo
. PulseAudio is a per-user service, hence the --user
flag.
Updated to leverage array iteration and module listing + property grep to reduce the amount of boilerplate.