Created
August 22, 2012 16:50
-
-
Save rvause/3427407 to your computer and use it in GitHub Desktop.
Simple script to make my computer beep at me when its about to die without battery
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
#!/usr/bin/env python | |
import subprocess | |
import time | |
import shlex | |
import re | |
percent = 100 | |
def command(string): | |
try: | |
call = subprocess.Popen( | |
shlex.split(string), | |
stdout=subprocess.PIPE, | |
stdin=subprocess.PIPE, | |
) | |
return call | |
except (OSError, ValueError): | |
pass | |
return None | |
while True: | |
call = command('acpi -b') | |
try: | |
percent = re.findall('([0-9]*\%)', call.stdout.read().strip())[0][:-1] | |
except IndexError: | |
pass | |
if int(percent) < 5: | |
call = command('mpg123 /home/rvause/bin/phone.mp3') | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment