Search code examples
bashconky

Why is execbar in conky not working with a variable


execbar in conky does not seem to be working properly.

So if I do in a bash script (named myscript.sh)

# moc or mocp is Music on Console
totalsec=$(mocp --info | grep "TotalSec" | cut -d: -f2 | sed 's/^ //g' | sed 's/ $//g')
cursec=$(mocp --info | grep "CurrentSec" | cut -d: -f2 | sed 's/^ //g' | sed 's/ $//g')
progress=$(echo "(${cursec}*100/${totalsec})" | bc)
echo "\${execbar echo ${progress}}"
echo "${progress}" # This works and shows be the value of the integer variable.

and then call the bash script from conky using

conky.text = [[${execpi 3 ./myscript.sh}]];

then progress bar is not shown. Only a white rectangle.

However, if the same bash script is changed to

progress=23
echo "\${execbar echo ${progress}}"

then it works and shows a constant bar of 23. Don't know why passing a integer variable is not working. Any help to solve this problem will be appreciated.


Solution

  • It turns out that execbar in a bash script can be made to work. Sort of.

    To focus the problem on just the variable issue, I made a little script (myscript2.sh) that just gets the seconds from the current time for display in the bar...

    #!/bin/bash
    progress=$(date --date='now' +%S)
    echo \${execbar echo ${progress}}
    

    ...and was able to get a periodically updated bar showing the seconds using this conky config file...

    conky.config = {
        alignment = 'top_left',
        minimum_width = 300,
        own_window = true,
        own_window_hints = 'below',
        own_window_type = 'desktop',
        own_window_argb_visual=true,
        own_window_transparent = true,
        update_interval = 2.0,
    }
    
    conky.text = [[
    ${execpi 3 ./myscript2.sh}
    ]]
    

    However, conky alternates bewteen showing the bar filled to the proper extent and showing the bar empty. In other words, the display of the bar contents blinks on and off. Yuck.

    As an alternative, by using a script (myscript3.sh) to simply return the value to be displayed in the bar...

    #!/bin/bash
    progress=$(date --date='now' +%S)
    echo $progress
    

    ...and changing the conky config file to use execibar rather than execpi...

    conky.config = {
        alignment = 'top_left',
        minimum_width = 300,
        own_window = true,
        own_window_hints = 'below',
        own_window_type = 'desktop',
        own_window_argb_visual=true,
        own_window_transparent = true,
        update_interval = 2.0,
    }
    
    conky.text = [[
    ${execibar 3 ./myscript3.sh}
    ]]
    

    ...it appears to work as intended, without any blinking.