Skip to content

Instantly share code, notes, and snippets.

@dominikwilkowski
Created September 29, 2024 07:13
Show Gist options
  • Save dominikwilkowski/b001924cc660430e06b304c6539feeb8 to your computer and use it in GitHub Desktop.
Save dominikwilkowski/b001924cc660430e06b304c6539feeb8 to your computer and use it in GitHub Desktop.
Toggle a HomeKit shortcut when the webcam is on

Toggle a HomeKit shortcut when the webcam is on

When working from home I have my desk and webcam pointing towards my door which means sometimes someone might enter my office just to find themself to be captured on camera unwittingly. To deal with this I added a light above the outside of my door. This light switches on when my webcam is on and off when it is off. This way people know if they are on camera or not.

door

This is how I did it:

1. Install OverSight

I installed OverSight which is a great security-minded open source tool that will send you a notification when your webcam or mic is on.

2. Create shortcuts for the devices you want to control

Open the Shortcuts app on your mac and create two short cuts for both events: enabling and disabling the camera.

shortcuts

3. Install the shell script

Then I wrote a small shell script to run either of these shortcuts:

#!/bin/bash

EVENT=""

while [[ $# -gt 0 ]]; do
	case "$1" in
		-event)
			if [[ -n "$2" ]]; then
				EVENT="$2"
				shift 2
			else
				echo "Error: '-event' requires an argument [on|off]."
				exit 1
			fi
			;;
		*)
			# Ignore other flags
			shift
			;;
	esac
done

if [[ "$EVENT" == "on" ]]; then
	shortcuts run "Turn OnAir Light On"
elif [[ "$EVENT" == "off" ]]; then
	shortcuts run "Turn OnAir Light Off"
else
	echo "Usage: $0 [other options] -event [on|off]"
	exit 1
fi

I placed this content into a file called ~/onair.sh and made it executable:

λ chmod +x ~/onair.sh

4. Call the script from the settings of OverSight

settings

Done

Now whenever my webcam is enabled the light goes on outside my office and people know if they're on camera or not.

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