Press "Enter" to skip to content

Auto-Pause for Zoom

I don’t like wearing headphones all day and since I’m lucky enough to have a spare room for an office, I can play music through my Bluetooth speaker. However, I’m lazy, and I don’t want to fiddle around with my music player just cause I’m starting a Zoom meeting. Thus, automation.

Zoom provides callbacks when meetings start, but that’s aimed at people writing plugin modules. OK, we can go a bit lower level. I can’t just watch for a process, cause Zoom is always running on my laptop. But I can watch for open UDP sockets!

$ lsof -i 4UDP | grep zoom
zoom.us 88028 bryantd 83u IPv4 0xa90f1ce03eca5d5 0t0 UDP xx.xx.xx.xx:57275
zoom.us 88028 bryantd 84u IPv4 0xa90f1ce03eca2ed 0t0 UDP xx.xx.xx.xx:52612
zoom.us 88028 bryantd 90u IPv4 0xa90f1ce09340175 0t0 UDP *:65048
zoom.us 88028 bryantd 91u IPv4 0xa90f1ce0939ce8d 0t0 UDP *:60088
zoom.us 88028 bryantd 95u IPv4 0xa90f1ce0939c8bd 0t0 UDP *:50594

That’ll do, pig. That’ll do.

#!/bin/bash

trap ctrl_c INT

function ctrl_c() {
        stop_music
        exit
}

function stop_music() {
        /usr/bin/osascript -e 'tell application "Music" to pause'
}

while true; do
        zoom_status=$( /usr/sbin/lsof -i UDP | /usr/bin/grep zoom | wc -l )

        if (( $zoom_status > 0 )); then
                stop_music
        fi

        sleep 30
done

I’m catching interrupts because I want a quick keyboard method to stop the music just in case. Right now I don’t think I want it to restart music when I leave a Zoom call, but easy enough to add that if I do.

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *