Is there an API, that can lock the screen as the menu bar entry you can add from Keychain
preferences?
This Keychain
function is (was) lock
To lock computer and show password promt for recent user you can use this code:
- (void)lockScreen
{
MDSendAppleEventToSystemProcess(kAESleep);
}
OSStatus MDSendAppleEventToSystemProcess(AEEventID eventToSendID)
{
AEAddressDesc targetDesc;
static const ProcessSerialNumber kPSNOfSystemProcess = {0, kSystemProcess};
AppleEvent eventReply = {typeNull, NULL};
AppleEvent eventToSend = {typeNull, NULL};
OSStatus status = AECreateDesc(typeProcessSerialNumber,
&kPSNOfSystemProcess, sizeof(kPSNOfSystemProcess), &targetDesc);
if ( status != noErr ) return status;
status = AECreateAppleEvent(kCoreEventClass, eventToSendID,
&targetDesc, kAutoGenerateReturnID, kAnyTransactionID, &eventToSend);
AEDisposeDesc(&targetDesc);
if ( status != noErr ) return status;
status = AESendMessage(&eventToSend, &eventReply,
kAENormalPriority, kAEDefaultTimeout);
AEDisposeDesc(&eventToSend);
if ( status != noErr ) return status;
AEDisposeDesc(&eventReply);
return status;
}