I have a script that needs to run every so often, but only if the screensaver is active or if the screen is asleep (to make sure nobody is actively using the computer first). I need to have a way to determine whether the screen is asleep from the command line. (One-liner preferred)
I'm using "ps -acxw | grep ScreenSaverEngine | grep -v grep" to determine if the screensaver is running, which always worked fine in previous OS versions, but in Mountain Lion, the screensaver is disabled when the screen goes to sleep, so I need a way to determine that as well now.
Help is appreciated...
4
then the screen is awake, if it returns a1
then the screen is asleep.ioreg -n IODisplayWrangler -r IODisplayWrangler -w 0 | sed -n 's/^.*"CurrentPowerState"=\([0-9]\+\).*/\1/p'