tim*_*ode 3 ruby macos sleep objective-c
有没有人知道查询OS X的方法,以便通过命令行或任何其他方法(无论是通过命令行进入系统睡眠状态还是激活显示器睡眠状态(甚至是磁盘睡眠状态),找出实际剩余的时间)例如Ruby或Objective-C)?
我认为通过命令行的pmset之类的东西可能提供了这些信息,但它似乎只显示和更新当前设置,而不是允许反馈操作系统当前循环的位置.
我的要求是我目前有一个Ruby脚本,我只想在我不使用机器的情况下运行,并且一个简单的'whatcher脚本'允许这样做,但是什么'看'是我需要的东西帮助.
似乎应该有一个简单的答案,但到目前为止我还没有找到任何明显的答案.有任何想法吗?
下面是一个bash脚本来显示命令,这有点复杂.想法是用户在节能器偏好窗格中设置系统休眠时间.当没有连接到计算机的设备移动那段时,系统实际上将进入休眠状态.因此,为了获得系统进入睡眠状态的时间,我们需要这两个结果之间的差异.
#!/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
Run Code Online (Sandbox Code Playgroud)