LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Conky question: How can you pass Conky variables to scripts? (http://www.linuxquestions.org/questions/linux-software-2/conky-question-how-can-you-pass-conky-variables-to-scripts-4175443380/)

evan1026 12-29-2012 11:55 AM

Conky question: How can you pass Conky variables to scripts?
 
So basically, I'm trying to make a battery bar that's colored based on the battery percentage. I've got a python script that makes the colors perfectly:
Code:

import os, sys
import string

def calccolor(percentage):
        red = (100 - percentage) * 255 / 100
        green = percentage * 255 / 100
        print("${color %02x%02x00}") % (red, green)

if __name__ == "__main__":
        percentage = sys.argv[1]
        calccolor(int(percentage))

but I can't seem to figure out how to run it in Conky. Currently I have:
Code:

Battery: ${execpi 10 python ~/batcalc.py $battery_percent}$battery_bar$color
but that doesn't work since Conky doesn't parse the percentage. Any way I can make this work?

evan1026 12-29-2012 07:52 PM

I figured it out but I'm gonna post in case anyone is googling something like this later or something like that. Now the conky line is
Code:

Battery: ${execpi 1 acpi -b | egrep -o "[0-9]+%" | xargs python ~/batcalc.py}$battery_percent% $battery_bar$color
and I changed the python script to
Code:

import os, sys
import string

def calccolor(percentage):
        red = (100 - percentage) * 255 / 100
        green = percentage * 255 / 100
        print("${color %02x%02x00}") % (red, green)

if __name__ == "__main__":
        percentage = sys.argv[1][0:-1]
        calccolor(int(percentage))



All times are GMT -5. The time now is 09:32 AM.