Created
March 23, 2020 08:51
-
-
Save nullxx/3fc89754fdaa4f3e90a84fc7b97cd007 to your computer and use it in GitHub Desktop.
Detectar cuando la corriente se desconecta y conecta para macOS. Se envía una alerta cuando se cambia el estado.
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
import subprocess | |
ut = subprocess.check_output(['pmset', '-g', 'batt']) | |
down = """"" | |
display dialog "LA CORRIENTE HA SIDO CORTADA\nMAS INFORMACION EN CONSOLA " ¬ | |
with title "Alerta corriente alterna general" ¬ | |
with icon caution ¬ | |
buttons {"OK"} | |
""" | |
up = """"" | |
display dialog "LA CORRIENTE HA SIDO ACTIVADA\nMAS INFORMACION EN CONSOLA " ¬ | |
with title "Alerta corriente alterna general" ¬ | |
with icon caution ¬ | |
buttons {"OK"} | |
""" | |
avisadoD = False | |
avisadoU = False | |
while (True): | |
ut = subprocess.check_output(['pmset', '-g', 'batt']) | |
if (avisadoD == False): | |
if ('discharging' in str(ut)): | |
subprocess.call("osascript -e '{}'".format(down), shell=True) | |
avisadoD = True | |
avisadoU = False | |
print(ut) | |
else: | |
if (avisadoU == False): | |
if ('discharging' not in str(ut)): | |
subprocess.call("osascript -e '{}'".format(up), shell=True) | |
avisadoU = True | |
avisadoD = False | |
print(ut) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment