Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MacOS - detect when camera is turned on/off

I want to automate a personal workflow that is based on camera usage on my MBP.

Basically I want to know if any of the cameras (built-in or USB) has been turned on or off, so I can run a program or script I'll create.

I think it's OK if I need to poll for the cameras statuses but an event or callback based solution would be ideal

like image 792
sergiopereira Avatar asked Mar 04 '20 22:03

sergiopereira


People also ask

How do I know if my camera is on on my Mac?

The camera automatically turns on when you open an app—such as FaceTime or Photo Booth—or use a feature—such as Markup or head pointer—that can use the camera. A green light beside the camera glows to indicate the camera is on.

Are Mac cameras always on?

The FaceTime HD camera built into your Mac computer is designed with your privacy in mind and uses a camera indicator light that glows green when the camera is active. So you will always know when the camera is on. The camera is engineered so that it can't activate without the camera indicator light also turning on.

Can Mac camera be hacked without the light?

The webcam indicator light randomly turns on Sure, it can be a software or hardware malfunction, but it is more likely to be your laptop camera being hacked. Can a MacBook camera be on without light? Apple assures its customers that the FaceTime HD camera cannot be used without enabling the indicator light.


2 Answers

log stream --predicate 'eventMessage contains "Post event kCameraStream"' works up to macOS Big Sur, but not in macOS Monterey. You'll have to use a slightly different predicate:

$ log stream --predicate 'subsystem contains "com.apple.UVCExtension" and composedMessage contains "Post PowerLog"'
Filtering the log data using "subsystem CONTAINS "com.apple.UVCExtension" AND composedMessage CONTAINS "Post PowerLog""
Timestamp                       Thread     Type        Activity             PID    TTL  
2021-10-27 12:21:13.366628+0200 0x147c5    Default     0x0                  353    0    UVCAssistant: (UVCExtension) [com.apple.UVCExtension:device] UVCExtensionDevice:0x1234005d7 [0x7fe3ce008ca0] Post PowerLog {
    "VDCAssistant_Device_GUID" = "00000000-1432-0000-1234-000022470000";
    "VDCAssistant_Power_State" = On;
}
2021-10-27 12:21:16.946379+0200 0x13dac    Default     0x0                  353    0    UVCAssistant: (UVCExtension) [com.apple.UVCExtension:device] UVCExtensionDevice:0x1234005d7 [0x7fe3ce008ca0] Post PowerLog {
    "VDCAssistant_Device_GUID" = "00000000-1432-0000-1234-000022470000";
    "VDCAssistant_Power_State" = Off;
}
like image 53
neu242 Avatar answered Sep 22 '22 12:09

neu242


This seems to work.

❯  log stream | grep "Post event kCameraStream"
2020-12-01 14:58:53.137796-0500 0xXXXXXX   Default     0x0                  XXX    0    VDCAssistant: [com.apple.VDCAssistant:device] [guid:0xXXXXXXXXXXXXXXXX] Post event kCameraStreamStart
2020-12-01 14:58:56.431147-0500 0xXXXXXX   Default     0x0                  XXX    0    VDCAssistant: [com.apple.VDCAssistant:device] [guid:0xXXXXXXXXXXXXXXXX] Post event kCameraStreamStop
2020-12-01 14:58:56.668970-0500 0xXXXXXX   Default     0x0                  XXX    0    VDCAssistant: [com.apple.VDCAssistant:device] [guid:0xXXXXXXXXXXXXXXXX] Post event kCameraStreamStart

Some of the numbers in the output are redacted with Xs because I don't know what they mean. :)

like image 21
Patrick McElhaney Avatar answered Sep 22 '22 12:09

Patrick McElhaney