77 lines
2.3 KiB
Python
Executable File
77 lines
2.3 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import subprocess
|
|
|
|
|
|
def view_details():
|
|
try:
|
|
details = subprocess.check_output(
|
|
["upower", "-i", "/org/freedesktop/UPower/devices/battery_BAT1"],
|
|
text=True
|
|
)
|
|
# Extraer información relevante si es necesario
|
|
subprocess.run(["notify-send", "Detalles de la Batería", details])
|
|
except subprocess.CalledProcessError as e:
|
|
subprocess.run(
|
|
["notify-send", "Error", "No se pudieron obtener los detalles de la batería."])
|
|
|
|
|
|
def check_health():
|
|
try:
|
|
health = subprocess.check_output(
|
|
["upower", "-i", "/org/freedesktop/UPower/devices/battery_BAT1"],
|
|
text=True
|
|
)
|
|
# Extraer información específica sobre la salud
|
|
energy_full = ""
|
|
for line in health.splitlines():
|
|
if "energy-full:" in line:
|
|
energy_full = line.split(":", 1)[1].strip()
|
|
break
|
|
if energy_full:
|
|
subprocess.run(["notify-send", "Salud de la Batería",
|
|
f"La capacidad máxima actual es {energy_full}."])
|
|
else:
|
|
subprocess.run(["notify-send", "Salud de la Batería",
|
|
"No se pudo determinar la capacidad máxima."])
|
|
except subprocess.CalledProcessError as e:
|
|
subprocess.run(
|
|
["notify-send", "Error", "No se pudo verificar la salud de la batería."])
|
|
|
|
|
|
def save_mode():
|
|
try:
|
|
# Reducir el brillo al 50% (asegúrate de tener xbacklight instalado)
|
|
subprocess.run(["xbacklight", "-set", "50"])
|
|
subprocess.run(
|
|
["notify-send", "Modo de Ahorro Activado", "Brillo reducido al 50%."])
|
|
except Exception as e:
|
|
subprocess.run(
|
|
["notify-send", "Error", "No se pudo activar el modo de ahorro."])
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) < 2:
|
|
subprocess.run(
|
|
["notify-send", "Error", "No se proporcionó ninguna acción."])
|
|
sys.exit(1)
|
|
|
|
action = sys.argv[1]
|
|
|
|
if action == "view_details":
|
|
view_details()
|
|
elif action == "check_health":
|
|
check_health()
|
|
elif action == "save_mode":
|
|
save_mode()
|
|
else:
|
|
subprocess.run(
|
|
["notify-send", "Error", f"Acción desconocida: {action}"])
|
|
sys.exit(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|