Skip to content

Instantly share code, notes, and snippets.

@nikhilw
Last active August 10, 2022 08:08
Show Gist options
  • Save nikhilw/daa2a2f99558b3278fc61023e73b0248 to your computer and use it in GitHub Desktop.
Save nikhilw/daa2a2f99558b3278fc61023e73b0248 to your computer and use it in GitHub Desktop.
Toggle mic on-off on a Ubuntu / Linux Mint machine with a keyboard shortcut
#! /bin/sh
# static icon, easier to set as a bash alias or directly use as a single command instead of creating a script file.
amixer set Capture toggle | gawk 'match($0, /Front Left.*\[(.*)\]/, a) {print a[1]}' | xargs notify-send --hint=int:transient:1 -i "audio-input-microphone" "Mic switched: $1"
#! /bin/sh
# With icon indicating the state of the mic
state=`amixer set Capture toggle | gawk 'match($0, /Front Left.*\[(.*)\]/, a) {print a[1]}'`
if [ $state = "off" ]; then
icon="audio-input-microphone-muted-symbolic"
else
icon="audio-input-microphone-symbolic"
fi
notify-send --hint=int:transient:1 -i $icon "Mic switched: $state"
@cednore
Copy link

cednore commented Mar 21, 2022

I needed this, Thank you.

@amatmv
Copy link

amatmv commented Aug 10, 2022

Thank you! It works perfectly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment