Search code examples
luaawesome-wm

How do I get local date / time as variable inside awesome wm rc.lua?


Basically, I want to have a printscreen key so I added into my rc.lua

awful.key({}, "Print", function() awful.util.spawn("flameshot screen -p /my/path/__date__time__.png") end)

to do the key binding.

How do I have date/time as variable in this command, so that the screenshot is savec under /my/path/2021-11-04_12-12 for example?


Solution

  • If os.date() is present than...

    awful.key({}, "Print", function() awful.util.spawn("flameshot screen -p /my/path/" .. os.date('%Y-%m-%d_%H-%M.png')) end)
    

    The os.date() function is able to return a formated time string.
    See also: https://www.lua.org/manual/5.4/manual.html#6.9