-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsleeputil.cpp
More file actions
51 lines (47 loc) · 1.64 KB
/
Copy pathsleeputil.cpp
File metadata and controls
51 lines (47 loc) · 1.64 KB
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
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <sys/sysctl.h>
#include <mach/mach.h>
#include <unistd.h> //geteuid();
#include <string.h>
char offargument[] = "--off";
char onargument[] = "--on";
kern_return_t get_privileges_status(){
if (geteuid() != 0){
return KERN_FAILURE;
} else if (geteuid() == 0){
//Got root
}
return KERN_SUCCESS;
}
int main(int argc, char *argv[])
{
if (argc < 2){
printf("Usage: sleeputil --off / --on\n");
return -1;
} else if (argc == 2){
if (get_privileges_status() == KERN_SUCCESS){
char *controlstring = new char[strlen(argv[1])];
strcpy(controlstring, argv[1]);
printf("Sleeputil by GeoSn0w (@FCE365)\nA wrapper around pmset I did for my own use.\nUse at your own risk!\n\nNOTE! Other processes may prevent sleep from occuring!\n\n");
if (strcmp(offargument, controlstring) == 0){
printf("Disabling sleep on this Mac...\n\n");
system("pmset -b sleep 0");
system("pmset -b disablesleep 1");
} else if (strcmp(onargument, controlstring) == 0){
printf("Enabling sleep on this Mac...\n\n");
system("pmset -b sleep 5");
system("pmset -b disablesleep 0");
} else {
printf("Usage: sleeputil --off / --on\n");
}
} else {
printf("Please run this program as root. Do that with sudo\n");
}
} else if (argc > 2){
printf("Too many arguments!\nUsage: sleeputil --off / --on\n");
return -1;
}
return 0;
}