Shortcut key to mute/unmute yourself in Zoom, Google Meet, or Teams

A custom and global shortcut key to mute / unmute yourself in Zoom or Google Meet
A custom and global shortcut key to mute / unmute yourself in Zoom or Google Meet

Just like everyone else, 2020 was the year of having more and more video-conference calls. How many times did we struggle to find the meeting window during a call, and say “Sorry, I was on mute”? I tried to address the pain and ended up with the following setup.

xdotool

xdotool is a great automation tool for X, and it can search a window, activate it, and simulate keyboard input. That’s a perfect match for the use case here.

Here is an example command for Google Meet.

$ xdotool search --name '^Meet - .+ - Chromium$' \
    windowactivate --sync \
    key ctrl+d

In the chained commands, it does:

  1. search windows named like Meet - <MEETING_ID> - Chromium
  2. activate the first window passed by the previous line and wait until it gets active (--sync)
  3. send a keystroke as Ctrl+D, which is the default shortcut in Meet

By the way, my main browser is Firefox, but I have to use Chromium to join Meet calls since it tends to have less CPU utilization.

You can do something similar for Zoom with Alt+A.

$ xdotool search --name '^Zoom Meeting$' \
    windowactivate --sync \
    key alt+a

Microsoft Teams should work with Ctrl+Shift+M at least for the web version.

$ xdotool search --name '^.* Microsoft Teams - Chromium$' \
    windowactivate --sync \
    key ctrl+shift+m

GNOME keyboard shortcuts

The commands above can be mapped to a shortcut key with GNOME.

It’s pretty simple, but some tricks may be required. As far as I see, gsd-media-keys will invoke a command when a shortcut key is pressed, not released. In my case, I use Super+Shift+A as the shortcut key, so Meet may recognize keys pressed as Super+Shift+A + Ctrl+D = Super+Shift+Ctrl+A+D which doesn’t trigger the mute/unmute behavior actually. Keys can be canceled with keyup, so the key command was turned into keyup shift+super+a in the end.

Also, I wanted to use the same shortcut key for multiple services, and I have the following line which tries Google Meet first, then Zoom if no Meet window is found. It should work most of the cases unless you join multiple meetings at the same time.

sh -c "
    xdotool search --name '^Meet - .+ - Chromium$'
        windowactivate --sync
        keyup shift+super+a key ctrl+d
    || xdotool search --name '^.* Microsoft Teams - Chromium$'
        windowactivate --sync
        keyup shift+super+a key ctrl+shift+m
    || xdotool search --name '^Zoom Meeting$'
        windowactivate --sync
        keyup shift+super+a key alt+a
"

--clearmodifiers can be used to simplify the whole commands, but when I tried, it sometimes left the Super or Shift key pressed depending on the timing I released the key.

Hardware mute/unmute button

Going further, I wanted to have a dedicated button to mute/unmute myself especially for some relaxed meetings where I don’t have to keep my hands on the keyboard all the time.

Back in October, I bought a USB volume controller, which is recognized as “STMicroelectronics USB Volume Control” from the OS. It was around 15 USD.

It emits expected events as KEY_VOLUMEUP and KEY_VOLUMEDOWN with the dial, and KEY_MUTE when the knob is pressed.

I created a “hwdb” file to remap the mute key to something else as follows in /etc/udev/hwdb.d/99-local-remap-usb-volume-control.hwdb.

# STMicroelectronics USB Volume Control
# Remap the click (Mute) to XF86Launch
evdev:input:b0003v0483p572D*
 KEYBOARD_KEY_c00e2=prog4

Once the hardware database is updated with systemd-hwdb update and the device is unplugged and plugged again (if without udevadm commands), I was able to map Launch4(prog4) to the xdotool commands in GNOME successfully.

It looks like everyone had the same idea. There are fancier buttons out there :-)

Related