Last active
February 8, 2023 23:56
-
-
Save jptoto/3b2197dd652ef13bd7f3cab0f2152b19 to your computer and use it in GitHub Desktop.
Catch camera event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Is there a way to read the output for macOS Monterey - I tried to merge these 2 together but get nothing but the out put text - it doesnt appear to read the state of on or off - any help appreciated.
If you add --style ndjson
to the command, every message is on one line. Then you can grep for e.g.'"VDCAssistant_Power_State" = On'
.
henrik242 thanks fella got there in the end 👌
Thanks for the comments! I hadn't even tried this on Monterey yet but good to know it works with some predicate changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work in macOS Monterey. You'll have to use a slightly different predicate: