Skip to content

Instantly share code, notes, and snippets.

@John-K
Created May 21, 2015 00:24
Show Gist options
  • Save John-K/6333786adbb6f1afca13 to your computer and use it in GitHub Desktop.
Save John-K/6333786adbb6f1afca13 to your computer and use it in GitHub Desktop.
bash oneliner: kill caffeinate when battery < 10% and not on AC power
while true; do VAR=`pmset -g batt|tr -d "'%;"`; if [ `echo $VAR | awk '{print $4}'` == 'Battery' ]; then if [ `echo $VAR|awk '{print $7}'` -lt 100 ]; then echo "Killing caffeinate"; pkill caffeinate; fi; fi; sleep 2; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment