Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file which contains one word, "green", "yellow" or "red" (this file is updated via a cron job.

I would like to use that color to display text in Conky. The actual text would stay the same, but the color would update depending on that file. Does anyone know of a way to make this work? Thanks!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Create a bash-script that outputs ${color yourcolor} :

#!/bin/bash

read -r </path/to/color-file color
echo -n '${color '$color'}'

And run it in conky (every 10 seconds):

${execpi 10 /path/to/script.sh} Colored text here {color}

Something nested like ${color ${head -1 /path/to/color-file}} might also work.

share|improve this answer
    
Thank you! Worked perfectly. –  Trevor Dec 9 '11 at 15:04
    
Here's an alternate line #4 for your script which will even work if your color file contains some garbage (e. g. control characters) beyond the 1st line for some reason: awk 'NR==1{print}' color-file. I'd always avoid cat in these cases because it is always risky to blindly assume the file will only contain one neat line. A blank line following the first line might already induce problems. –  syntaxerror Oct 11 at 13:08
    
You're right @syntaxerror I edited the answer and also updated the bash-script –  micke Oct 11 at 15:28
    
Looks pretty good now, thanks for the quick update ... except that I'm still not sure that this will work in Conky without the first $ in the echo line being escaped with a backslash. Conky is always picky about these things.:) Even though I might be wrong. –  syntaxerror Oct 11 at 17:38
    
Nah, it's cool. No need for escaping inside single quotes. –  micke Oct 11 at 21:24

Note that you will need execp or execpi to do the above as exec and execi do not parse the output of the script

execp: Executes a shell command and displays the output in conky. warning: this takes a lot more resources than other variables. I'd recommend coding wanted behaviour in C and posting a patch. This differs from $exec in that it parses the output of the command, so you can insert things like ${color red}hi!${color} in your script and have it correctly parsed by Conky. Caveats: Conky parses and evaluates the output of $execp every time Conky loops, and then destroys all the objects. If you try to use anything like $execi within an $execp statement, it will functionally run at the same interval that the $execp statement runs, as it is created and destroyed at every interval.

This also works with simply cat'ing a file such as:

${execpi 15 cat /path/to/file.log}
share|improve this answer
1  
This is not an answer to the original question. –  DavidPostill Sep 7 at 11:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.