2

Today I made a fresh installation of Ubuntu 14.04. I was using Ubuntu 10.04 previously. So far I have restored everything except for I cannot find an applet for Awesome WM that shows the battery status. How are we supposed to get that when using Ubuntu 14.04? It was so much easier with Ubuntu 10.04 where I could just run the power manager from Gnome on startup.

1 Answer 1

2

Just did it yesterday for my laptop :)

To get the battery status there is quite simple tool called acpi, you need to install it first:

sudo apt-get install acpi

Then if you run it you'll have something like this:

acpi
Battery 1: discharging, 44%, 00:18:48 remaining

So now you just need to create a widget which will run this command and the output in on the wibox - to display it.

For awesome 3.4:

batterywidget = widget({ type = "textbox" })                                    
batterywidget.text = " | Battery | "                                            
batterywidgettimer = timer({ timeout = 5 })                                     
batterywidgettimer:add_signal("timeout",                                        
  function()                                                                    
    fh = assert(io.popen("acpi | cut -d, -f 2,3 -", "r"))                       
    batterywidget.text = " |" .. fh:read("*l") .. " | "                         
    fh:close()                                                                  
  end                                                                           
)                                                                               
batterywidgettimer:start()

For awesome 3.5:

batterywidget = wibox.widget.textbox()    
batterywidget:set_text(" | Battery | ")    
batterywidgettimer = timer({ timeout = 5 })    
batterywidgettimer:connect_signal("timeout",    
  function()    
    fh = assert(io.popen("acpi | cut -d, -f 2,3 -", "r"))    
    batterywidget:set_text(" |" .. fh:read("*l") .. " | ")    
    fh:close()    
  end    
)    
batterywidgettimer:start()

And then add it to wibox in your rc.lua:

right_layout:add(batterywidget)
1
  • Holy smokes, @streetturtle! This worked really nicely. Thanks.
    – erapert
    Apr 13, 2016 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.