Skip to content

Instantly share code, notes, and snippets.

@typcn
Created March 29, 2016 03:40
Show Gist options
  • Save typcn/58e23804101b0ba1470d to your computer and use it in GitHub Desktop.
Save typcn/58e23804101b0ba1470d to your computer and use it in GitHub Desktop.
Unlock & Lock your mac
extern void SACLockScreenImmediate ( );
SACLockScreenImmediate();
io_registry_entry_t r = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/IOResources/IODisplayWrangler");
if (r) {
IORegistryEntrySetCFProperty(r, CFSTR("IORequestIdle"), kCFBooleanFalse);
IOObjectRelease(r);
}
NSString *pw = [SSKeychain passwordForService:@"login" account:@"login"];
NSString *s = @"tell application \"System Events\"\n\
tell application \"ScreenSaverEngine\" to quit\n\
delay 0.5\n\
keystroke \"%@\"\n\
keystroke return\n\
end tell";
NSDictionary *err;
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:s,pw]];
[script executeAndReturnError:&err];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment