Mac OS X - Send the OS to sleep
Posted: Sun Dec 06, 2015 2:27 am
Code: Select all
RunProgram("/usr/bin/pmset", "sleepnow", "")
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
RunProgram("/usr/bin/pmset", "sleepnow", "")
Code: Select all
; PB 5.40+
; For security purposes, caller must be root or the console user
#MACH_PORT_NULL = 0
ImportC "-framework IOKit"
IOPMFindPowerManagement(master_device_port)
IOPMSleepSystem(fb)
IOServiceClose(connect)
EndImport
fb = IOPMFindPowerManagement(#MACH_PORT_NULL)
If #MACH_PORT_NULL <> fb
err = IOPMSleepSystem(fb)
If err
Debug "error"
EndIf
IOServiceClose(fb)
EndIfAnd what's the Code behind the RunProgram function? Yes, it's such ObjC code -fsw wrote:In ObjectiveC:In PureBasic:Code: Select all
NSTask *pmsetTask = [[NSTask alloc] init]; pmsetTask.launchPath = @"/usr/bin/pmset"; pmsetTask.arguments = @[@"sleepnow"]; [pmsetTask launch];Easy.Code: Select all
RunProgram("/usr/bin/pmset", "sleepnow", "")