Skip to content

Instantly share code, notes, and snippets.

@kates
Last active August 29, 2015 14:02
Show Gist options
  • Save kates/b5f052e75e3c52ccac1d to your computer and use it in GitHub Desktop.
Save kates/b5f052e75e3c52ccac1d to your computer and use it in GitHub Desktop.
lock macosx screen from terminal
make
./lockscreen
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
#import <IOKit/IOKitLib.h>
int main() {
io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if (r) {
IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanTrue);
IOObjectRelease(r);
}
return 0;
}
TARGET=lockscreen
all: clean compile
compile:
clang -framework Foundation -framework IOKit main.m -o ${TARGET}
clean:
rm -f ${TARGET}
.PHONY: all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment