Skip to content

Instantly share code, notes, and snippets.

@haukurk
Last active October 28, 2017 11:45
Show Gist options
  • Save haukurk/bc561b998db16a68402b7cae7ef52477 to your computer and use it in GitHub Desktop.
Save haukurk/bc561b998db16a68402b7cae7ef52477 to your computer and use it in GitHub Desktop.
Lock OSX without going to sleep.
cat > main.m <<EOF

#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;
}

EOF

# 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