LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-29-2012, 10:55 AM   #1
evan1026
LQ Newbie
 
Registered: Dec 2012
Posts: 4

Rep: Reputation: Disabled
Question 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?

Last edited by evan1026; 12-29-2012 at 12:47 PM.
 
Old 12-29-2012, 06:52 PM   #2
evan1026
LQ Newbie
 
Registered: Dec 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
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))
 
  


Reply

Tags
conky, python



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
conky question: passing conky-variable to shell-script zlin50 Linux - Software 2 12-29-2012 06:47 PM
LXer: Configure conky-Lua in Ubuntu (11.10 & 12.04), Fedora, debian and LinuxMint | Howto Conky LXer Syndicated Linux News 0 03-06-2012 12:40 PM
LXer: Conky Colors Makes Your Conky Beautiful In Seconds (Version 3.20 Released) LXer Syndicated Linux News 0 08-01-2010 11:21 AM
Conky: problems displaying output from certain scripts or commands zymos Linux - Software 1 09-10-2009 05:59 PM
Conky on Suse 10.0 - *** buffer overflow detected *** conky terminated Slidex Linux - Software 1 03-17-2006 11:50 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration