Programmatically put a Mac into sleep

后端 未结 6 1017
清歌不尽
清歌不尽 2021-02-03 13:21

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?

6条回答
  •  太阳男子
    2021-02-03 13:53

    You can also use scripting bridge. Draft code is

    SystemEventsApplication *systemEvents = [SBApplication applicationWithBundleIdentifier:@"com.apple.systemevents"];
    [systemEvents sleep]; 
    

提交回复
热议问题