Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save davemay99/e5ba468093b74d4680d1f2563e613810 to your computer and use it in GitHub Desktop.
Save davemay99/e5ba468093b74d4680d1f2563e613810 to your computer and use it in GitHub Desktop.
Catch camera event
#!/bin/bash
# Begin looking at the system log via the steam sub-command. Using a --predicate and filtering by the correct
# subsystem first improves CPU performance DRASTICALLY. Then just pull out the camera event
log stream --predicate 'subsystem == "com.apple.VDCAssistant" && eventMessage CONTAINS[c] "Post event kCameraStream"'| while read line; do
# If we catch a camera start event, turn the light on
if echo "$line" | grep -q "Post event kCameraStreamStart"; then
echo "Camera has been activated, turn on the light."
curl -s -o /dev/null http://192.168.1.198/gpio/1
fi
# If we catch a camera stop event, turn the light off.
if echo "$line" | grep -q "Post event kCameraStreamStop"; then
echo "Camera shut down, turn off the light."
curl -s -o /dev/null http://192.168.1.198/gpio/0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment