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

Does anyone know a way to request OS X to find out how much time is actually left before it enters system sleep or activates sleep mode (or even sleep mode), either through the command line or any other method (e.g. Ruby or Objective-C)?

I thought something like pmset through the command line might have suggested this information, but apparently it only shows and updates the current settings, and does not allow getting feedback from where in the current OS loop.

My requirement is that I currently have a Ruby script that I would like to run only when I am not using the machine, and a simple "whatcher script" would allow this, but what to look for 'I need a little help.

There seems to be a simple answer, but so far I have not found anything obvious. Any ideas?

+2
source share
1 answer

Heres a bash script to show commands that are a bit complicated. The idea is that the user sets the system’s sleep time in the area of ​​energy-saving preferences. The system will actually go into sleep mode if the device is not connected to the computer at this time. Therefore, in order to get the time before the system falls asleep, we need the difference between these two 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 
+5
source

Source: https://habr.com/ru/post/1401768/


All Articles