Skip to content

Instantly share code, notes, and snippets.

@rvause
Created August 22, 2012 16:50
Show Gist options
  • Save rvause/3427407 to your computer and use it in GitHub Desktop.
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
#!/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