-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
41 lines (32 loc) · 1.08 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdlib.h>
#include <stdio.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
io_connect_t root_port;
void
sleepCb(void* refCon, io_service_t service, natural_t messageType, void* messageArgument) {
switch (messageType) {
case kIOMessageCanSystemPowerOff:
case kIOMessageCanSystemSleep:
case kIOMessageSystemWillSleep:
system("osascript -e \"set Volume 0\"\n");
IOAllowPowerChange(root_port, (long)messageArgument);
default:
break;
}
}
int main(int argc, char **argv) {
IONotificationPortRef notifyPortRef;
io_object_t notifierObject;
void* refCon = NULL;
root_port = IORegisterForSystemPower(refCon, ¬ifyPortRef, sleepCb, ¬ifierObject);
if (root_port == 0)
{
printf("IORegisterForSystemPower failed\n");
return 1;
}
CFRunLoopAddSource(CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes);
CFRunLoopRun();
return 0;
}