Last active
August 21, 2022 11:55
-
-
Save jvalrog/7f3954ef56524be196edd29c3ac2dab1 to your computer and use it in GitHub Desktop.
Mute/Unmute individual Pulseaudio's streams using Rofi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
######################################################### | |
# | |
# PAMUTE | |
# | |
# Mute/Unmute individual Pulseaudio's streams using Rofi. | |
# | |
# Requires: | |
# - pactl | |
# - gawk | |
# - rofi | |
# | |
# Configure your rofi options here: | |
# | |
ROFI_OPTIONS="-p 'Audio Streams: ' -width 600" | |
# | |
######################################################### | |
pactl list sink-inputs | awk -v rofi_cmd="rofi -dmenu -format i $ROFI_OPTIONS" ' | |
BEGIN { item = 1 } | |
/^Sink Input/ { | |
if (item in sinks) | |
item++ | |
split($0, result, "#") | |
sinks[item]["sink"] = result[2] | |
next | |
} | |
/application\.name/ { | |
split($0, result, "\"") | |
sinks[item]["name"] = result[2] | |
next | |
} | |
/application\.process\.binary/ { | |
split($0, result, "\"") | |
sinks[item]["binary"] = result[2] | |
next | |
} | |
/Mute:/ { | |
sinks[item]["muted"] = ($2 == "yes" ? 1 : 0) | |
next | |
} | |
END { | |
if (length(sinks) == 0) { | |
print("NO STREAMS FOUND") | rofi_cmd | |
exit | |
} | |
print("UNMUTE ALL") |& rofi_cmd | |
for (item in sinks) { | |
muted = (sinks[item]["muted"] ? "\xf0\x9f\x94\x87" : "\xf0\x9f\x94\x8a") | |
print(muted " " sinks[item]["name"] " (" sinks[item]["binary"] ")") |& rofi_cmd | |
} | |
close(rofi_cmd, "to") | |
rofi_cmd |& getline selected | |
if (selected != "") { | |
if (selected == 0) { | |
for (item in sinks) { | |
system("pactl set-sink-input-mute " sinks[item]["sink"] " 0") | |
} | |
} else { | |
system("pactl set-sink-input-mute " sinks[selected]["sink"] " toggle") | |
} | |
} | |
} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Screenshot in action: