Free Like GNU

It's GNU for you!
← zsnes on OLPC XO
Browse the OLPC Koji Repository →

Get battery status in XFCE on OLPC

Post on December 27th, 2007 by francisco athens

Genmon is a wonderful XFCE panel plugin for providing the status of just about anything. Using the trusty “grep” and “awk” tools we can format the output of a command to fit nicely inside of the genmon plugin. Here is a tutorial to make it work and give new users a chance to see the usefulness of “grep” and “awk”. This is assuming you have XFCE running on your machine (XO or otherwise) to use the genmon plugin, but the first part will be about polling HAL that you can do from the TERMINAL activity in Sugar too! HAL is short for hardware abstraction layer and is a way to interface with the hardware to get information or change how a device works. There is a battery monitor plugin for XFCE but it does not seem to like the XO way of doing stuff, so we will make our own.

  • open the terminal in Sugar or XFCE and run hal-device to list all the devices interfaced by HAL

$ hal-device

  • lots of text will zip by quickly, lets narrow it down with a pipe ( | is the shifted \ key! ) and grep

$ hal-device | grep battery

  • the one we will focus on has to do with the battery level percentage and this looks fairly unique

$ hal-device | grep charge_level.percentage

  • you will now have just a single line telling you the name of the property and the values. we are only concerned with the number itself so we can further pipe the output to awk

$ hal-device | grep charge_level.percentage | awk '{print $3}'

  • a single value in decimal will appear because we use awk to give us the 3rd piece of output (seperated by space characters)
  • let’s get fancy and plop a “%” behind it! ` are backticks found under the ~ key, things within them will execute and output before continuing on. We’ll take our command and encapsulate it within the echo command which just outputs whatever its given. Be careful not to confuse single quotes with quotes and backticks!

$ echo `hal-device | grep charge_level.percentage | awk '{print $3}'`%

  • you should now have a nicely formated value with a % sign for garnish Lets make a script of it. (genmon does not like complicated commands) ~ is your home folder (probably /home/olpc )

$ nano ~/bat_p.sh

  • add the command we created to this file and ctrl-x to save and exit. then make it exectutable

$ chmod +x ~/bat_p.sh

  • test it

$ ~/bat_p.sh

Read on if you have XFCE and want to put the output in your panel.

Pages: 1 2

Category OLPC, gnu-fu | 1 Comment »

One Response to “ Get battery status in XFCE on OLPC ”

  1. # 1 LITENVERDEN.ORG » Blog Archive » Moving To Xfce On The XO Says:
    January 12th, 2008 at 1:25 pm

    [...] Adding Battery Status (2) [...]

  • Gallery

    olpc_xfce.png
  • Comments

    • DaVi on Also selling my TC1100…
    • francisco athens on New HP 2710p and Notes
    • P3t3r on Ubuntu on OLPC XO
    • P3t3r on Ubuntu on OLPC XO
    • sanity on Holger’s Backported AMD Video Drivers Accelerate Ubuntu on OLPC
  • Tags

    2710p Alix Art Education backlight Blue Line Riders chicago cl corporateagendas ebay Elephants Dream FOSS GNU HAL iftop Inhabitants of Dreams installation Journalism kids linux drivers multitouch nand NFLG OLPC OLPC News pedway proprietarymadness PXE shell sugar Tablet TC1100 Ubuntu underground visual culture Wayan Vata wifi wii wiimote wiki Wrapped in Plastic xfce XO xorg xubuntu zsnes
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Blogroll

    • Development Blog
    • Documentation
    • Planet OLPC
    • Plugins
    • Suggest Ideas
    • Support Forum
    • Themes
    • WordPress Planet
  • Eyes Open

    • BoingBoing
    • Defective Yeti
    • LXer
  • Very GNU

    • Chicago GNU/Linux User Group
    • Free Software Foundation
    • Planet Debian
    • Planet OLPC
    • Xubuntu


Free Like GNU © 2007 All Rights Reserved.
Using WordPress Engine

sumenep 1.0 made by Nurudin Jauhari
Entries and Comments