Need help with an .lua script for conky please [SOLVED]

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Post Reply
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Need help with an .lua script for conky please [SOLVED]

Post by Logansfury »

Hello everyone,

I am working with a weather conky, and the return from the weather site api comes in lowercase. I have a script to format provided text - in this case the variable "wetter[1]" - into all words first letter capitolized.

Unfortunately what works in a terminal doesnt work in conky, I'm sure I did something wrong. Can anyone help?

Original code:

Code: Select all

write_text(cr, 20,20,wetter[1], {align="l", size=12, bold=true, color="0xff0000"})
My edit attempt:

Code: Select all

write_text(cr, 20,20,{execi 60 echo wetter[1] | awk '{for(i=1;i<=NF;i++){$i=toupper(substr($i,1,1)) tolower(substr($i,2))}}'
, {align="l", size=12, bold=true, color="0xff0000"})
Can anyone see where I messed up?
Last edited by Logansfury on Fri Feb 09, 2024 3:33 am, edited 1 time in total.
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
User avatar
Bleys
Level 4
Level 4
Posts: 431
Joined: Wed Apr 20, 2022 4:17 am
Location: Essen, Germany

Re: Need help with an .lua script for conky please

Post by Bleys »

Logansfury wrote: Wed Feb 07, 2024 4:12 am Hello everyone,

I am working with a weather conky, and the return from the weather site api comes in lowercase. I have a script to format provided text - in this case the variable "wetter[1]" - into all words first letter capitolized.

Unfortunately what works in a terminal doesnt work in conky, I'm sure I did something wrong. Can anyone help?

Original code:

Code: Select all

write_text(cr, 20,20,wetter[1], {align="l", size=12, bold=true, color="0xff0000"})
LUA itself can handle this. Paste this Function:

Code: Select all

function firstCharUp(str)
    return (str:gsub("^%l", string.upper))
end
bevor the Line: function conky_main()

call:

Code: Select all

write_text(cr, 20,20,firstCharUp(wetter[1]), {align="l", size=12, bold=true, color="0xff0000"})
Ryzen 5 5600G, 16GB RAM, 2TB M.2 Crucial P3, Asrock Deskmeet X300, Samsung Odyssey 49", Linux Mint 21
User avatar
Logansfury
Level 6
Level 6
Posts: 1237
Joined: Fri Oct 27, 2023 4:08 pm
Location: Las Vegas NV, USA

Re: Need help with an .lua script for conky please

Post by Logansfury »

Hello Bleys :)

I actually already found the solution to this online but forgot to mark the post as [SOLVED].

I used this line of code:

Code: Select all

wetter[1] = string.gsub(wetter[1], "%f[%l]%l", string.upper)
Image <-- Cick for sudo inxi --usb -Fxxxnmprz output, updated hourly!
Post Reply

Return to “Compiz, Conky, Docks & Widgets”