Skip to content

Instantly share code, notes, and snippets.

@cicorias
Created May 18, 2017 16:37
Show Gist options
  • Save cicorias/65280637dc795c18c896b75fea255885 to your computer and use it in GitHub Desktop.
Save cicorias/65280637dc795c18c896b75fea255885 to your computer and use it in GitHub Desktop.
macOS lock screen 1 line command
# Do our work in the temporary directory that gets cleaned on boot
cd /tmp
# Create the source file
cat > main.m <<END_OF_FILE
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
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;
}
END_OF_FILE
# Compile the source file
clang -framework Foundation main.m -o lockscreen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment