1/*
2cc -g -o /tmp/setaggro setaggro.c -framework ApplicationServices -framework IOKit -Wall
3*/
4
5#include <CoreFoundation/CoreFoundation.h>
6#include <ApplicationServices/ApplicationServices.h>
7#include <IOKit/graphics/IOGraphicsTypesPrivate.h>
8#include <IOKit/pwr_mgt/IOPMLib.h>
9#include <stdlib.h>
10#include <stdio.h>
11
12#ifndef sub_iokit_graphics
13#define sub_iokit_graphics           err_sub(5)
14#endif
15
16#ifndef kIOFBLowPowerAggressiveness
17#define kIOFBLowPowerAggressiveness     iokit_family_err(sub_iokit_graphics, 1)
18#endif
19
20#ifndef kIODisplayDimAggressiveness
21#define kIODisplayDimAggressiveness     iokit_family_err(sub_iokit_graphics, 3)
22#endif
23
24int main(int argc, char * argv[])
25{
26    kern_return_t err;
27    io_connect_t  connect;
28    unsigned long value;
29
30    if (argc < 2)
31    {
32        fprintf(stderr, "%s value\n", argv[0]);
33        return (1);
34    }
35
36    connect = IOPMFindPowerManagement(kIOMasterPortDefault);
37    if (!connect)
38    {
39        fprintf(stderr, "IOPMFindPowerManagement(%x)\n", err);
40        return (1);
41    }
42
43    value = strtol(argv[1], 0, 0);
44
45#if 1
46    err = IOPMSetAggressiveness( connect, kIOFBLowPowerAggressiveness, value );
47    fprintf(stderr, "IOPMSetAggressiveness(kIOFBLowPowerAggressiveness, %lx) result %x\n", value, err);
48#else
49    err = IOPMSetAggressiveness( connect, kIODisplayDimAggressiveness, value );
50    fprintf(stderr, "IOPMSetAggressiveness(kIODisplayDimAggressiveness, %lx) result %x\n", value, err);
51#endif
52    IOServiceClose(connect);
53
54    exit (0);
55    return (0);
56}
57
58