Guest User

Untitled

a guest
Mar 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. sleeptime=60
  4.  
  5. BatteryAlert(){
  6. percentage=$(pmset -g batt | egrep "([0-9]+\%).*" -o | cut -f1 -d';' | sed 's/%//' | bc)
  7. alertlevel=10
  8.  
  9. if [ "$percentage" -le "$alertlevel" ]
  10. then
  11. if [ ! -f "./batteryalert_lock" ]
  12. then
  13. /usr/bin/osascript <<-EOF
  14. tell application "System Events"
  15. activate
  16. display dialog "Your battery is at $percentage%. It is recommended you plug into a power outlet, or shut down!"
  17. end tell
  18. EOF
  19.  
  20. touch ./batteryalert_lock
  21. fi
  22.  
  23. echo "Battery life is at $percentage%. Battery is running low."
  24.  
  25. elif [ "$percentage" -gt "$alertlevel" ]
  26. then
  27. echo "Battery life is at $percentage%. No need to worry... yet."
  28.  
  29. if [ -f "./batteryalert_lock" ]
  30. then
  31. rm ./batteryalert_lock
  32. fi
  33.  
  34. else
  35. echo "Error"
  36. # Do nothing
  37. fi
  38. }
  39.  
  40. while (true)
  41. do
  42. BatteryAlert;
  43. sleep $sleeptime;
  44. done
Add Comment
Please, Sign In to add comment