1
I am writing a small bash script in Linux to control Pulseaudio inputs/outputs.
What I want to do is to route all sink-inputs, except one, into one or another sink. The sink-input I don't want to route is this one:
pi@raspberrypi:~/fonction $ pactl list sink-inputs
Sink Input #36062
Driver: protocol-native.c
Owner Module: 2
Client: 198
Sink: 2
Sample Specification: s16le 2ch 44100Hz
Channel Map: front-left,front-right
Format: pcm, format.sample_format = "\"s16le\"" format.rate = "44100" format.channels = "2" format.channel_map = "\"front-left,front-right\""
Corked: no
Mute: no
Volume: front-left: 65536 / 100% / 0.00 dB, front-right: 65536 / 100% / 0.00 dB
balance 0.00
Buffer Latency: 120000 usec
Sink Latency: 236349 usec
Resample method: n/a
Properties:
media.name = "ALSA Playback"
application.name = "ALSA plug-in [snapclient]"
native-protocol.peer = "UNIX socket client"
native-protocol.version = "32"
application.process.id = "539"
application.process.user = "snapclient"
application.process.host = "raspberrypi"
application.process.binary = "snapclient"
application.language = "C"
application.process.machine_id = "69e523231bb44f2e926a758a63cbb5b1"
module-stream-restore.id = "sink-input-by-application-name:ALSA plug-in [snapclient]"
To move a sink-input to another sink I need to use this command:
pactl move-sink-input <sink-input id> <sink id>
So I have to parse the result of the first command to get the Sink Input #ID (contained in the first line) but I have to use a condition to check if module-stream-restore.id (last line) is really what I want to route.
I'd need something like:
if [ <last line> = 'sink-input name I need' ]
then
pactl move-sink-input <id from first line> <my sink name>
fi
I just don't know how to parse the command to get BOTH information.
Right now, I am able to get only the last line, or only the #ID.
pactl list short sink-inputs|while read stream; do
streamId=$(echo $stream )
id=$(echo pactl list sink-inputs | grep module-stream-restore.id | grep -o '".*"' |sed 's/"//g')
if [ "$streamId" != 'sink-input-by-application-name:ALSA plug-in [snapclient]' ]
then
pactl move-sink-input "$streamId" Snapcast
fi
How do I proceed to parse the result of pactl list sink-inputs so I can read two elements, not just one, in each "block" (aka, each sink-input) of the result of that command in a bash script?
Why dont you save the sink input number in a variable? – Nifle – 2018-02-07T13:17:09.780
You can get ther first line and the last line with
head -n1andtail -n1orsed '1!d'andsed '$!d'– Paulo – 2018-02-07T13:17:43.787@Nifle, the sink-input number could change anytime. – TurboGraphxBeige – 2018-02-07T16:35:42.347
@Paulo, I'll give it a try tonight. It might be just what I need. – TurboGraphxBeige – 2018-02-07T16:36:45.543