Skip to content

Instantly share code, notes, and snippets.

@knikolla
Created February 7, 2016 18:14
Show Gist options
  • Select an option

  • Save knikolla/fc6983df5913608bcb09 to your computer and use it in GitHub Desktop.

Select an option

Save knikolla/fc6983df5913608bcb09 to your computer and use it in GitHub Desktop.
Send a dbus message to upower to refresh device state every 5 seconds.
#!/usr/bin/python
# There is an issue with the power indicator on rMBP 13".
# upower doesn't indicate AC/Batt event change until it polls
# the device after 30 seconds of inactivity.
# Since 30 seconds is too long, using this script I force it
# to refresh after 5 seconds by using the dbus.
import os
import time
while True:
os.system('dbus-send --print-reply \
--system \
--dest=org.freedesktop.UPower \
/org/freedesktop/UPower/devices/battery_BAT0 \
org.freedesktop.UPower.Device.Refresh')
time.sleep(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment