je cherchais un utilitaire qui m'aurait permis de connaître mon niveau de batterie facilement, sans passer par un système lourd comme des desklets ou gnome-power-manager. Je voulais du KISS.
Donc j'ai fait ça en Python, et j'en suis assez satisfait. Ça affiche une notification standard, comme network-manager par exemple. Perso, j'appelle ce script via un Super-B, mais on peut s'arranger avec cron pour qu'il nous le lance toutes les 20 minutes par exemple.
Donc, voilà le machin :
Code : Tout sélectionner
#!/usr/bin/python2
import sys
import time
import os
import pynotify
import commands
import pyinotify
encharge = commands.getoutput("acpi -a | grep 'on'")
vol = commands.getoutput("acpi -b | grep 'Battery 0' | awk '{ print $4}' | cut -d '%' -f1")
etat2 = "Batterie"
print(encharge)
if encharge == "":
encharge = ""
else:
encharge = "-plugged"
if vol != "":
vol = int(vol)
if vol < 10:
etat = 'notification-battery-000%s' % (encharge)
etat2 = "Batterie faible"
elif vol < 20:
etat = 'notification-battery-010%s' % (encharge)
etat2 = "Batterie faible"
elif vol < 30:
etat = 'notification-battery-020%s' % (encharge)
etat2 = "Batterie faible"
elif vol < 40:
etat = 'notification-battery-030%s' % (encharge)
elif vol < 50:
etat = 'notification-battery-040%s' % (encharge)
elif vol < 60:
etat = 'notification-battery-050%s' % (encharge)
elif vol < 70:
etat = 'notification-battery-060%s' % (encharge)
elif vol < 80:
etat = 'notification-battery-070%s' % (encharge)
elif vol < 90:
etat = 'notification-battery-080%s' % (encharge)
elif vol < 100:
etat = 'notification-battery-090%s' % (encharge)
else:
etat = 'notification-battery-100%s' % (encharge)
vol = str(vol)
vol = vol + "%"
else:
etat = 'notification-power-disconnected'
etat2 = "Pas de batterie"
vol = "Ordinateur sur secteur"
commande = "notify-send -i %s '%s' '%s'" % (etat, etat2, vol)
print(commande)
os.popen(commande)
Je vais peut être améliorer le système pour afficher le temps restant avant la charge/décharge complète.
Qu'en pensez-vous ?