OS X直到(系统/显示/磁盘)睡眠的时间? [英] OS X time until (system/display/disk) sleep?

查看:101
本文介绍了OS X直到(系统/显示/磁盘)睡眠的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道一种查询OS X的方法,以便找出通过命令行或其他方式进入系统睡眠或激活显示睡眠(甚至磁盘睡眠)之前实际剩余的时间.其他方法(例如Ruby或Objective-C)?

Does anyone know of a way to query OS X in order to find out how much time is actually left before it enters either system sleep or activates the display sleep (or even disk sleep), either via the command line, or any other method (Ruby or Objective-C for instance)?

我以为通过命令行pmset之类的东西可能已经提供了此信息,但是它似乎仅显示和更新当前设置,而不允许反馈操作系统当前所在的位置.

I thought something like pmset via the command line might have offered this information, but it appears to only show and update what the current settings are, rather than allow feedback of where in the cycle the OS currently is.

我的要求是,我目前有一个Ruby脚本,仅当我不使用机器时才想运行它,而一个简单的"whatcher脚本"将允许这样做,但是观察"的是我要的东西需要一点帮助.

My requirement is that I currently have a Ruby script that I'd like to run only when I'm not using the machine and a simple 'whatcher script' would allow this, but what to 'watch' is the thing I need a little help with.

似乎应该有一个简单的答案,但是到目前为止,我还没有发现任何明显的问题.有什么想法吗?

It seems like there should be a simple answer, but so far I've not found anything obvious. Any ideas?

推荐答案

使用bash脚本显示命令,有些复杂.这个想法是,用户可以在节能器"首选项窗格中设置系统睡眠时间.在这段时间内,没有任何连接到计算机的设备移动时,系统实际上将进入睡眠状态.因此,为了获得直到系统进入睡眠状态的时间,我们需要这两个结果之间的差值.

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

这篇关于OS X直到(系统/显示/磁盘)睡眠的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆