Skip to content

Instantly share code, notes, and snippets.

@teklynk
Created February 7, 2026 04:17
Show Gist options
  • Select an option

  • Save teklynk/e295ead7d1d8e6e5fd1f187fc6344060 to your computer and use it in GitHub Desktop.

Select an option

Save teklynk/e295ead7d1d8e6e5fd1f187fc6344060 to your computer and use it in GitHub Desktop.
Toggle Webcam on off
#!/usr/bin/env bash
# enable / disable all UVC devices/cameras
# No arguments - auto‑toggle based on whether the uvcvideo module is loaded
# on = force load the driver
# off = force unload the driver
if [[ -z "$DISPLAY" ]]; then
export DISPLAY=:0
fi
ACTION="$1"
if [[ -z "$ACTION" ]]; then
# Toggle: if the module is exists then unload it, else load it
if lsmod | grep -q '^uvcvideo'; then
ACTION="off"
else
ACTION="on"
fi
fi
case "$ACTION" in
off)
sudo modprobe -r uvcvideo && \
echo "All UVC cameras disabled" && \
play /usr/share/mint-artwork/sounds/unplug.oga 2>/dev/null & \
notify-send "Turning UVC Cameras Off..."
;;
on|*)
sudo modprobe uvcvideo && \
echo "All UVC cameras enabled" && \
play /usr/share/mint-artwork/sounds/plug.oga 2>/dev/null & \
notify-send "Turning UVC Cameras On..."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment