Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. acpi_battery = %x[ acpi -b ]
  4.  
  5. if acpi_battery.empty?
  6. puts "Battery not conected. Exiting."
  7. exit
  8. end
  9.  
  10. $battery_status = acpi_battery.split(' ')[2].gsub(',', '')
  11. $battery_percentage = acpi_battery.split(' ')[3].gsub('%,', '').to_i
  12.  
  13. def notification message, urgency, icon
  14. command = "notify-send --urgency=#{ urgency } 'Battery at #{ $battery_percentage }%' '\n #{ message }'"
  15.  
  16. if not icon.nil?
  17. command += " --icon #{ icon }"
  18. end
  19.  
  20. system command
  21. end
  22.  
  23. def wall message
  24. system "sudo wall 'Battery at #{ $battery_percentage }% \n #{ message }'"
  25. end
  26.  
  27. u = 'critical'
  28. i = '/usr/share/icons/HighContrast/scalable/emblems/emblem-important.svg'
  29.  
  30. if $battery_status == "Discharging"
  31. case $battery_percentage
  32. when 10..19
  33. m = "Not long left. Get the power cord."
  34. u = 'normal'
  35. i = nil
  36.  
  37. when 6..9
  38. m = "Plug-in the power cord."
  39.  
  40. when 3..5
  41. m = "Wrap it up!"
  42.  
  43. when 1..2
  44. m = "Oh, well... guess it's important..."
  45.  
  46. when 0
  47. m = "Your're own your own. Good Luck!"
  48.  
  49. else
  50. m = nil
  51.  
  52. end
  53.  
  54. notification(m, u, i) if not m.nil?
  55. end
  56.  
  57. if $battery_status == "Charging"
  58. if (80..100).include? $battery_percentage
  59. notification "Enough charging!", u, i
  60. end
  61. end
  62.  
  63. puts "Battery at #{ $battery_percentage }%"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement