Tuesday, February 10, 2009

Detecting whether AC power is on

Info from following URL:
  http://mychael.gotdns.com/blog/2008/06/showing-battery-life-in-awesome-with-lua/

    Recently, another recording on my Eee PC was cut off because the AC power was not switched on. I found the URL above and modified the bash script NOT to launch Audacity unless power is switched on.
    Steps:
  1. Press Ctrl-Alt-T to open the terminal console.
  2. I had previously set the Audacity icon in my Favorites to launch "audacity-checklist".
    So in this case, I would type "sudo kwrite /usr/bin/audacity-checklist".
  3. Delete the line that runs the command "audacity" and replace with the following (the awk command is on one line):

    #check if power is switched on and prevent launching if not so.
    powerStatus=$(awk '{ print $2 }' /proc/acpi/ac_adapter/AC0/state)

    if [ $powerStatus != "on-line"]
    then
       kdialog --msgbox "POWER IS NOT SWITCHED ON! \n\n Audacity will not launch."
    else
       audacity
    fi

    exit 0

  4. Try running the bash script with the power switched on and with it turned off.
(^ v ^)

No comments: