Skip to content

Instantly share code, notes, and snippets.

@nullxx
Created March 23, 2020 08:51
Show Gist options
  • Save nullxx/3fc89754fdaa4f3e90a84fc7b97cd007 to your computer and use it in GitHub Desktop.
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.
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