Skip to content

Instantly share code, notes, and snippets.

@bharadwaj-raju
Created June 3, 2016 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bharadwaj-raju/43919cbba4c2bca8145afb6af8d2a96d to your computer and use it in GitHub Desktop.
Save bharadwaj-raju/43919cbba4c2bca8145afb6af8d2a96d to your computer and use it in GitHub Desktop.
#!/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