I noticed that /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
and Keychain Access's Lock Screen (open its Preferences, check 'Show keychain status in menu bar' then hit Lock Screen from the status bar icon.) has different functionality. Is there any way to run Keychain Access's Lock Screen from command-line through Terminal.app or Cocoa API?
Mac OS 10.9. Thanks!
Press Command+Space to open Spotlight Search. Type “Terminal” in the Search bar, and then click it when it appears in the search results. Your Mac will now be in sleep mode. If you selected the option to require a password to wake it, it is now also effectively locked.
Go to Apple menu > System Preferences > Security & Privacy. If the lock at the bottom left is locked, click on it and type in your password. In the General tab, uncheck the box next to Require password. Confirm by clicking Turn Off Screen Lock.
Your login keychain password is normally the same as your user password (the password you use to log in to the computer). At login, if your keychain password somehow differs from your user password, it doesn't automatically unlock, and you're asked to enter the keychain's password.
I just found a solution for this: https://apple.stackexchange.com/a/123738/72534
#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;
}
Save as lockscreen.m
and compile with:
clang -framework Foundation -o lockscreen lockscreen.m
Works perfectly, as it just calls the same routine as the status bar icon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With