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
Preston is right, I use the following method and it works like a charm:
- (void)lockScreen {
NSTask *task;
NSArray *arguments = [NSArray arrayWithObject:@"-suspend"];
task = [[NSTask alloc] init];
[task setArguments: arguments];
[task setLaunchPath: @"/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession"];
[task launch];
[task release];
NSLog(@"screen is Locked");
}