Created
April 23, 2016 22:15
-
-
Save cardi/3e2b527a2ec819d51916604528986e93 to your computer and use it in GitHub Desktop.
os x lock screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <objc/runtime.h> | |
#import <Foundation/Foundation.h> | |
/* | |
lockscreen.m | |
to compile: | |
clang -framework Foundation lockscreen.m -o lockscreen | |
then bind a keyboard shortcut (e.g., with Hammerspoon or automator) | |
to run this program | |
original post: | |
http://apple.stackexchange.com/questions/80058/lock-screen-command-one-liner | |
original authors: | |
- http://apple.stackexchange.com/users/72534/jnk | |
- http://apple.stackexchange.com/users/68832/mrb | |
*/ | |
int main () { | |
NSBundle *bundle = [NSBundle bundleWithPath:@"/Applications/Utilities/Keychain Access.app/Contents/Resources/Keychain.menu"]; | |
Class principalClass = [bundle principalClass]; | |
id instance = [[principalClass alloc] init]; | |
[instance performSelector:@selector(_lockScreenMenuHit:) withObject:nil]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment