Closed MinmoTech closed 2 years ago
F main(program_name) { .... }
- it will use the built in command line automatic arguments parsing facilityprogram_name = read() - Sfx("\n")
of coursepw-link ${outputs[0]} ${inputs[0]}
to $(pw-link ${outputs[0]} ${inputs[0]})
Use command line arguments available in ARGV
: program_name = read() - Sfx("\n")
becomes program_name = ARGV[0]
.
Let us know how it goes
Unrelated improvement suggestion: .split("\n")
-> .lines()
and (EXPR - Sfx("\n")).split("\n")
also -> EXPR.lines()
If I understand correctly,
if not(Bool(ExitCode(`pactl list short sinks | grep combine`)))
can become
if not($(pactl list short sinks | grep combine))
Edit: alternatively:
if not(`pactl list short sinks`.has('combine'))
Thanks a lot, this is perfect! And with your tips my script looks a lot more readable now:
#!/usr/bin/env ngs
if not(`pactl list short sinks`.has('combine')){
$(pactl load-module module-null-sink media.class=Audio/Sink sink_name=combine channel_map=stereo)
}
program_name = ARGV[0]
outputs = `pw-link --output | grep -i ${program_name}`.lines()
inputs = `pw-link --input | grep combine`.lines()
pw-link ${outputs[0]} ${inputs[0]}
pw-link ${outputs[1]} ${inputs[1]}
And thank you for this project, I like it a lot since I found it thanks to your console interview!
I'm making a script that reroutes audio with pipewire on my PC. For this I have to pass the name of an appliation.
Currently I'm doing this with
echo "ProgramName" | my_script.ngs
but ideally I'd be able to use this by doingmy_script.ngs "ProgramName"
. I could also do this by making a wrapper script in another scripting language, but that also doesn't feel right.Thanks for any help!
My script in question: