Programmatically put a Mac into sleep
问题 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? 回答1: #include <stdio.h> #include <CoreServices/CoreServices.h> #include <Carbon/Carbon.h> SendAppleEventToSystemProcess(kAESleep); OSStatus SendAppleEventToSystemProcess(AEEventID EventToSend) { AEAddressDesc targetDesc; static const ProcessSerialNumber kPSNOfSystemProcess = { 0, kSystemProcess }; AppleEvent eventReply = {typeNull