-
Notifications
You must be signed in to change notification settings - Fork 0
/
ismicmuted.sh
33 lines (24 loc) · 1.1 KB
/
ismicmuted.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
#little script made for KDE command output widget to show if my mic is muted or not
#define colors here do `printf "%b"`` to set color
#use like so ${red} etc to put directly next to strings
resetcolor='\e[0m'
green='\e[1;32m'
red='\e[1;31m'
# Get active audio source index
CURRENT_SOURCE=$(pactl info | grep "Default Source" | cut -f3 -d" ")
# List lines in pactl after the source name match and pick mute status
Muted=$(pactl list sources | grep -A 10 $CURRENT_SOURCE | grep "Mute: yes")
#Mic Mute Status logic from here https://askubuntu.com/a/1291627
##test echo Muted variable for debugging
# echo $Muted
#if statement for checking if mic is muted or not ([-n ] checks if the variable is null or not) https://unix.stackexchange.com/a/109631
if [ -n "$Muted" ]; then
#printf Muted with mic on right side in red
#use {}around variables to have no spaces between var and string
printf "%b" "${red}Muted ${resetcolor}"
else
#printf Unmuted with mic on left side in Green
printf "%b" "${green} Unmuted${resetcolor}"
fi
#printf formatting from here https://stackoverflow.com/a/5412825