I can\'t find any instructions how to put a Mac programmatically into sleep mode (in Objective-C). I\'m sure it should be only one line, but could you give me a hint?
Tom is correct. The AE methods fail if the display is sleeping. pmset sleepnow works 100%.
NSTask *pmsetTask = [[NSTask alloc] init]; pmsetTask.launchPath = @"/usr/bin/pmset"; pmsetTask.arguments = @[@"sleepnow"]; [pmsetTask launch];