Просмотр исходного кода

Add notifcations when battery is low
Use sudo to ensure hibernate happens [Is there a better way?]

Andrew Swistak 12 лет назад
Родитель
Сommit
cf6785bb6c
2 измененных файлов с 15 добавлено и 5 удалено
  1. 4 3
      openbox/menu.xml
  2. 11 2
      scripts/auto-hibernate.sh

+ 4 - 3
openbox/menu.xml

@@ -220,15 +220,16 @@
       <execute>pkill -KILL -u $USER</execute>
       <execute>pkill -KILL -u $USER</execute>
     </action>
     </action>
   </item>
   </item>
+  <!--TODO: Find a way to not use sudo/editing sudoers-->
   <item label="Suspend">
   <item label="Suspend">
     <action name="Execute">
     <action name="Execute">
-      <execute>systemctl suspend</execute>
+      <execute>sudo systemctl suspend</execute>
     </action>
     </action>
   </item>
   </item>
   <item label="Hibernate">
   <item label="Hibernate">
     <action name="Execute">
     <action name="Execute">
       <prompt>Hibernate?</prompt>
       <prompt>Hibernate?</prompt>
-      <execute>systemctl hibernate</execute>
+      <execute>sudo systemctl hibernate</execute>
     </action>
     </action>
   </item>
   </item>
   <item label="Restart">
   <item label="Restart">
@@ -240,7 +241,7 @@
   <item label="Shutdown">
   <item label="Shutdown">
     <action name="Execute">
     <action name="Execute">
       <prompt>Shutdown?</prompt>
       <prompt>Shutdown?</prompt>
-      <execute>shutdown -p now</execute>
+      <execute>sudo shutdown -p now</execute>
     </action>
     </action>
   </item>
   </item>
 </menu>
 </menu>

+ 11 - 2
scripts/auto-hibernate.sh

@@ -2,6 +2,15 @@
 
 
 stat=$(cat /sys/class/power_supply/BAT0/uevent | grep STATUS | cut -f2 -d=)
 stat=$(cat /sys/class/power_supply/BAT0/uevent | grep STATUS | cut -f2 -d=)
 batperc=$(cat /sys/class/power_supply/BAT0/uevent | grep CAPACITY | cut -f2 -d=)
 batperc=$(cat /sys/class/power_supply/BAT0/uevent | grep CAPACITY | cut -f2 -d=)
-if [[ $stat -eq "Discharging" ]] && [[ $batperc -eq "5" ]]; then
-  /usr/bin/systemctl hibernate
+if [[ $stat -eq "Discharging" ]]; then
+  export DISPLAY=:0.0
+  if [[ $batperc -le 7 ]]; then
+    # This will, and should, spam me when my battery gets low.
+    notify-send 'Battery is low!' 'Save your work, idiot!' --icon=battery-low
+  fi
+  if [[ $batperc -eq 0 ]]; then
+    # TODO: Find a way to not use sudo/editing sudoers
+    notify-send 'Doing you a favor, buddy.' --icon=battery-low
+    sleep 2 && sudo /usr/bin/systemctl hibernate
+  fi
 fi
 fi