OS X time until (system/display/disk) sleep?

∥☆過路亽.° 提交于 2019-12-03 09:41:45

Heres a bash script to show the commands, which are a little complicated. The idea is that the user sets the system sleep time in the energy saver preference pane. The system will actually go to sleep when no device attached to the computer has moved for that time. So to get the time until the system goes to sleep we need the difference between those 2 results.

#!/bin/bash

# this will check how long before the system sleeps
# it gets the system sleep setting
# it gets the devices idle time
# it returns the difference between the two
#
# Note: if systemSleepTimeMinutes is 0 then the system is set to not go to sleep at all
#

systemSleepTimeMinutes=`pmset -g | grep "^[ ]*sleep" | awk '{ print $2 }'`

if [ $systemSleepTimeMinutes -gt "0" ]; then
    systemSleepTime=`echo "$systemSleepTimeMinutes * 60" | bc`
    devicesIdleTime=`ioreg -c IOHIDSystem | awk '/HIDIdleTime/ {print $NF/1000000000; exit}'`
    secondsBeforeSleep=`echo "$systemSleepTime - $devicesIdleTime" | bc`
    echo "Time before sleep (sec): $secondsBeforeSleep"
    exit 0
else
    echo "The system is set to not sleep."
    exit 0
fi
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!