Last active
August 29, 2015 14:24
-
-
Save lukestanley/6866cf075c0ab8076c2c to your computer and use it in GitHub Desktop.
Battery Alarm - run red alert sound if power is unplugged
This file contains 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
#download mp3 from http://soundbible.com/81-Red-Alert.html | |
from time import sleep #load a delay function | |
from os import system #load the "system" call function | |
import subprocess #load subprocess module | |
maybeRunningAlertSound = False #store if we are playing sounds, we are not yet | |
#Because "True" is always true, this is a good way to run the program forever: | |
while True is True: | |
#run a system command called acpi and get it's output: | |
powerStatus = subprocess.check_output('acpi -a', shell=True) | |
if 'off-line' in powerStatus: | |
#run red alert mp3 with app called mpg123: | |
system('mpg123 /home/luke/bin/Red_Alert_sound.mp3 &') | |
maybeRunningAlertSound = True | |
else: #we have the power cable plugged in and working | |
if maybeRunningAlertSound:#so now we can disable any alerts | |
system('killall mpg123') #kill the sound program called mpg123 | |
maybeRunningAlertSound = False #we know not to run killall again for now | |
sleep(1) #wait a second before we check again |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment