Created
April 4, 2013 04:29
-
-
Save aasmith/5307829 to your computer and use it in GitHub Desktop.
Determine if the screen is currently in power saving mode on OS X. This will probably break sometime after 10.8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the possible max power state and current power states for the device. | |
# If they all match (i.e. the current state is the same as the max state), | |
# then the screen is assumed to be on. | |
power_management = `ioreg -n IODisplayWrangler |grep -i IOPowerManagement` | |
power_states = power_management.scan(/(?:"\w+PowerState"=(\d))+/) | |
abort "Not enough power states!" if power_states.size < 2 | |
screen_on = power_states.uniq.size == 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment