Read more

How to: Build a "generic observer" widget for the awesome window manager

Arne Hartherz
May 15, 2013Software engineer at makandra GmbH

If you want a widget for awesome Show archive.org snapshot that runs a command regularly (every X seconds) and puts the output into your awesome panel, this is for you.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Put the code below into your ~/.config/awesome/rc.lua. It supplies two methods:

  • execute_command will run a command and return its output. Multiple lines will be joined into one line. The code is from the awesome wiki Show archive.org snapshot .

  • widget_with_timeout is a method that takes a command to run and a timeout in seconds. It'll return an object which contains a widget that you can put into your panel.
    ^
    -- From: http://awesome.naquadah.org/wiki/Awesome_3_configuration
    function execute_command(command)
    local fh = io.popen(command)
    local str = ""
    for i in fh:lines() do
    str = str .. i
    end
    io.close(fh)
    return str
    end

    -- Helper function to build all you need
    function widget_with_timeout(command, seconds)
    local object = {}
    object.command = command
    object.widget = widget({ type = "textbox" })

    object.update = function ()
      local result = execute_command(object.command)
      object.widget.text = " " .. awful.util.escape(result) .. " "
    end
    
    object.timer = timer({ timeout = seconds })
    object.timer:add_signal("timeout", object.update)
    object.timer:start()
    
    object.update() -- Initialize immediately
    return object
    

    end

Now use it in your rc.lua like this:

-- Get current track from DeaDBeeF, every 3 seconds
nowplaying = widget_with_timeout('deadbeef --nowplaying "%a - %t"', 3)

-- Remember to add the widget to your panel:

mywibox[s].widgets = {
  ...,
  nowplaying.widget,
  ...
}
Arne Hartherz
May 15, 2013Software engineer at makandra GmbH
Posted by Arne Hartherz to makandra dev (2013-05-15 16:28)