Created
June 3, 2016 06:54
-
-
Save bharadwaj-raju/43919cbba4c2bca8145afb6af8d2a96d to your computer and use it in GitHub Desktop.
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 | |
apps_to_save = ['Gedit', 'Writer'] | |
battery_limit = 10 # in percent | |
def get_battery_percentage(): | |
percentage, err = subprocess.Popen([r'upower -i $(upower -e | grep BAT) | grep --color=never -E percentage | xargs | cut -d ' ' -f2 | sed s/%// | |
'], shell=True, stdout=subprocess.PIPE).communicate() | |
return(int(percentage)) | |
while True: | |
if get_battery_percentage() <= battery_limit: | |
for app in apps_to_save: | |
app_window_ids = subprocess.Popen(['xdotool', 'search', '--class', app], | |
stdout=subprocess.PIPE) | |
out, err = app_window_ids.communicate() | |
for app_window_id in out.splitlines(): | |
subprocess.Popen(['xdotool', 'windowactivate', app_window_id, | |
';', 'xdotool', 'key', 'ctrl+s'], shell=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment