A Go program for macOS that detects whether your Studio Display's built-in camera is currently active using modern AVFoundation APIs.
- Uses AVFoundation (no deprecated APIs)
- Detect if the Studio Display camera is ON or OFF
- List all available video devices
- Watch mode for real-time monitoring
- Quiet mode for scripting
- Custom device name matching
# Build the program
go build -o studio-cam-detector studio-cam-detector.go
# Check Studio Display camera status
./studio-cam-detector
# List all video devices
./studio-cam-detector --list
# Monitor for changes
./studio-cam-detector --watch
# Quiet mode (outputs only ON/OFF)
./studio-cam-detector --quiet--list: List all video devices and exit--watch: Monitor for status changes--quiet: Output only ON/OFF--name <substring>: Match devices by name--interval <duration>: Polling interval for watch mode
Uses macOS's modern AVFoundation framework to:
- Enumerate video capture devices
- Check each device's
isInUseByAnotherApplicationproperty - Match devices by name (defaults to "Studio Display")
This approach uses current APIs and avoids deprecated CoreMediaIO functions.
Check if your Studio Display camera is active:
./studio-cam-detector
# Output: Studio Display Camera is OFFUse in a script:
if [ "$(./studio-cam-detector --quiet)" = "ON" ]; then
echo "Camera is active!"
fiMonitor for changes:
./studio-cam-detector --watch
# Output: Studio Display Camera [OFF]
# (when camera turns on)
# Output: Studio Display Camera [ON]You can set up the studio camera detector to automatically start when you log in using macOS's launchd system. A launchd plist file (com.wogri.studio-cam-detector.plist) is included in the project.
-
Copy the plist file to your user's LaunchAgents directory:
cp com.wogri.studio-cam-detector.plist ~/Library/LaunchAgents/ -
Load the service:
launchctl load ~/Library/LaunchAgents/com.wogri.studio-cam-detector.plist -
Start the service immediately (optional):
launchctl start com.wogri.studio-cam-detector
Check if the service is running:
launchctl list | grep com.wogri.studio-cam-detectorStop the service:
launchctl stop com.wogri.studio-cam-detectorUnload the service:
launchctl unload ~/Library/LaunchAgents/com.wogri.studio-cam-detector.plistView logs:
tail -f logs/studio-cam-detector.log
tail -f logs/studio-cam-detector.error.logThe service automatically:
- Starts the camera detector when you log in
- Runs the
startup.shscript which monitors your Studio Display camera - Executes
hass_off.shwhen the camera turns off - Executes
hass_on.shwhen the camera turns on - Keeps the service running and restarts it if it crashes
- Logs output to files in the
logs/directory
This is perfect for integrating with home automation systems or other workflows that need to respond to camera state changes.