Search code examples
luaconky

How do I cycle through random fonts in Conky via LUA?


This question here seems to tangentially touch upon it but I cannot get it to work. Here is my LUA file:

function conky_myeval()
   local myTable = { " Old London :normal:size=7", "Ethnocentric :normal:size=7"}
   var1 = myTable[ math.random( #myTable)] 
   return var1
end

and the related conky part:

${font ${lua conky_myeval}} Hello World!

Thank you for any assistance and I apologize if this has been asked before; The most similar I found I posted above.


Solution

  • I've found it easier to have a lua script pass conky a string that can be parsed by a lua_parse object that then generates the intended object rather than trying to pass a value to the intended object.

    In the case of random fonts, I'd do something like the following, which worked when tested.

    Lua file:

    function conky_myfont()
       local myTable = {"DejaVu Serif:normal:size=12", "MuseJazz Text:normal:size=12"}
       var1 = myTable[ math.random( #myTable)] 
       return "${font "..var1.."}"
    end
    

    Conky part:

    ${lua_parse conky_myfont}Hello World!${font}