2

I would like to perform basic, arbitrary maths without writing a lua function for it.

One (non-working) example might be: ${${loadavg 1}*100)}% If this were possible then many other uses might be imagined.

  • Now that I think about it, 0.16 might actually be my average CPU usage but I'd still like to know how to do basic math in Conky variables. – bp. Oct 20 '16 at 7:46
2

The answer depends on how you look at it. If you consider Conky's built-in Lua support and the associated use of Lua to be part of Conky, then yes. Otherwise, no.

Using Lua to do calculations is fairly straightforward. Here's an example Lua file called temps.lua for doing some calculations (I threw in your example, too)...

function conky_F2C(f)
    local c = (5.0/9.0)*(f-32.0)
    return c
end

function conky_C2F(c)
    local f = c*(9.0/5.0)+32.0
    return f
end

function conky_acpitempF()
    local c = conky_parse("${acpitemp}")
    return conky_C2F(c)
end

function conky_loadavg()
    return conky_parse("${loadavg 1}") * 100
end

At the top of the conky.config section of my .conkyrc file, I put the following...

lua_load = '~/bin/lua_scripts/temps.lua',

And in the conky.text section, I put the following lines...

ACPI Temp... ${acpitemp}°C
Conv to F... ${lua conky_acpitempF}°F

Body Temp... 98.6°C
Conv to C... ${lua conky_F2C 98.6}°C

Load Avg... ${loadavg 1}
Multipliled by 100... ${lua conky_loadavg}%

The resulting display on Conky should appear similar to...

ACPI Temp... 43°C
Conv to F... 109.4°F

Body Temp... 98.6°C
Conv to C... 37°C

Load Avg... 0.28
Multipliled by 100... 28.0%

Note that, as far as I've been able to tell, you can't pass a Conky object like ${loadavg 1} to a Lua function. But you can access an object within a Lua function as in the example code above.

| improve this answer | |

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.