Skip to content

Instantly share code, notes, and snippets.

@aasmith
Created April 4, 2013 04:29
Show Gist options
  • Save aasmith/5307829 to your computer and use it in GitHub Desktop.
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.
# 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