You are not logged in.

#1 2011-08-02 17:24:21

kairu
Member
Registered: 2011-08-02
Posts: 7

Bash Scripting with Conky -- How to implement?

Hey Folks, my first post here and I'm looking for a bit of help. I've created a bash script to work with conky in which its purpose is to change the color of the battery bar depending on current voltage.

Here's the bash script:

#!/bin/bash
# Change Conky battery color depending on charge

chrg=`cat /proc/acpi/battery/BAT1/state | grep "remaining capacity" | 
awk '{print $3 }'`

echo $chrg

if [ $chrg -lt "3499" ]; then
   ${color red}${battery_percent BAT1}% ${battery_bar 4 BAT1}
elif [ "$chrg" -lt "5100"]; then
   ${color orange}${battery_percent BAT1}% ${battery_bar 4 BAT1}
else ${color green}${battery_percent BAT1}% ${battery_bar 4 BAT1}
fi

Essentially what it is supposed to do is grab and store the "remaining capacity" and if its lower than a certain point it changes color. What I'm having trouble with is actually implementing the colors into conky. Right now all it is doing is printing the charge as you can see. Any help would be appreciated. Thanks!

Offline

#2 2011-08-02 17:35:58

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Bash Scripting with Conky -- How to implement?

I could be wrong, but I think conky uses colors defined in .conkyrc or whichever config file you have from conky. colors from an external script won't be rendered correctly.


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#3 2011-08-02 17:39:22

kairu
Member
Registered: 2011-08-02
Posts: 7

Re: Bash Scripting with Conky -- How to implement?

Yeah, that's kind of what I was thinking because everytime I put it in it is just the color of the previous item. Is Conky able to read bash scripts directly? As if I were to put the script in my .conkyrc?

Offline

#4 2011-08-02 18:14:41

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Bash Scripting with Conky -- How to implement?

yes, you will have to output the whole struct with the color though. So have your script output the following depending on the charge left

${color red} ${battery_percent BAT1}% ${color}
${color orange} ${battery_percent BAT1}% ${color}
${color green} ${battery_percent BAT1}% ${color}

then simply call the script from conky to be executed lets say every 30 mins

 execi 1800 sh /path/to/script

you might have to make the script executable ...


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#5 2011-08-02 18:39:51

kairu
Member
Registered: 2011-08-02
Posts: 7

Re: Bash Scripting with Conky -- How to implement?

I must be outputting it wrong. I've tried

echo '${color red}${battery_percent BAT1}% ${battery_bar 4 BAT1}${color}'

and even tried throwing it in a variable although I'm pretty sure thats the same thing. I'm not exactly experience with bash to be honest.

Offline

#6 2011-08-02 18:53:22

ibrunton
Member
From: Canada
Registered: 2011-05-05
Posts: 270

Re: Bash Scripting with Conky -- How to implement?

You need

execpi 1800 sh /path/to/script

in your .conkyrc for conky to parse the colours.

Last edited by ibrunton (2011-08-02 18:54:07)

Offline

#7 2011-08-02 19:10:31

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: Bash Scripting with Conky -- How to implement?

Can't you do it with conky's built-in if_match?

Offline

#8 2011-08-02 22:06:25

kairu
Member
Registered: 2011-08-02
Posts: 7

Re: Bash Scripting with Conky -- How to implement?

Hey Procyon, looks like that is working for me. I think I almost have it dialed in but I just need to make sure i dont have more than 1 bar showing up. Here's what I have:

${battery_percent BAT1}% ${if_match ${battery_percent BAT1} >= 65 }${color green}${battery_bar 4 BAT1}${color}${endif}${if_match ${battery_percent BAT1} <=64 }${color orange}${battery_bar 4 BAT1}${color}${endif}${if_match ${battery_percent BAT1} <=25 }${color red${battery_bar 4 BAT1}${color}${endif}

Thanks so much!

Offline

#9 2011-08-02 22:08:33

Inxsible
Forum Fellow
From: Chicago
Registered: 2008-06-09
Posts: 9,183

Re: Bash Scripting with Conky -- How to implement?

kairu wrote:

Hey Procyon, looks like that is working for me. I think I almost have it dialed in but I just need to make sure i dont have more than 1 bar showing up. Here's what I have:

${battery_percent BAT1}% ${if_match ${battery_percent BAT1} >= 65 }${color green}${battery_bar 4 BAT1}${color}${endif}${if_match ${battery_percent BAT1} <=64 }${color orange}${battery_bar 4 BAT1}${color}${endif}${if_match ${battery_percent BAT1} <=25 }${color red${battery_bar 4 BAT1}${color}${endif}

Thanks so much!

24 < 25 == true
24 < 64 == true

Meaning that for all values 25 and less, it will try to show 2 bars.

For the orange one, you will have to add in a lower limit as well. I am not sure how to do that since I was not even familiar with if_match. But see if conky has a built-in if_between


Forum Rules

There's no such thing as a stupid question, but there sure are a lot of inquisitive idiots !

Offline

#10 2011-08-02 22:28:16

kairu
Member
Registered: 2011-08-02
Posts: 7

Re: Bash Scripting with Conky -- How to implement?

Oh, I see. Hm, that is a problem...well the orange at least. I think the green and red are done I'm just working on orange. And unfortunatly there is no if_between func.

Offline

#11 2011-08-18 05:08:06

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: Bash Scripting with Conky -- How to implement?

Try this (I'm not sure if it will work):

${battery_percent BAT1}% ${if_match ${battery_percent BAT1} >= 65 }${color green}${battery_bar 4 BAT1}${color}${endif}${if_match ${battery_percent BAT1} <=25 }${color red}${battery_bar 4 BAT1}${color}${else}${color orange}${battery_bar 4 BAT1}${color}${endif}

Last edited by rockin turtle (2011-08-18 05:08:55)

Offline

#12 2014-03-05 01:28:22

mrknify
Member
Registered: 2013-01-18
Posts: 18

Re: Bash Scripting with Conky -- How to implement?

I had this issue, took me three days to solve. Using if_match, put all your if_matches in a line, with each option having its color of choice, then put the bar, or % at the end.  You will need to make sure it is in sequential order so the color will not overlap the color you want for the state in the if_match. I know this is an old thread, I will edit my post when I get on my netbook with the code.

I found this thread on a google search for bash and conky usages.

[edit] here was my solution for the if_match using the battery.

${if_match ${battery_percent BAT1} <= 49}${color0}${endif}${if_match ${battery_percent BAT1} <= 20}${color9}${endif}${if_match ${battery_percent BAT1} >= 50}${color4}${endif}${battery BAT1} ${alignr}${battery_bar 6,160 BAT1}

I have my colors set yellow for 49% and below, red 20% and lower, and last green for 50% and higher. Essentially this will pick yellow for under 49% and the if_match for red under 20%, the red will override the yellow, this is why order is important.

Remember this is all in one line, now there are cleaner ways of setting this up using lua. That is something I am still working on.

Last edited by mrknify (2014-03-05 17:09:59)


LG x110-L.a7b2a9 16g sd card, Arch Linux.(he has xp, oz unity, oz ultimate.)
Asus U36JC plan for duel boot w7 with Arch

Offline

#13 2014-03-07 15:02:31

easysid
Member
From: India
Registered: 2013-01-01
Posts: 256

Re: Bash Scripting with Conky -- How to implement?

Post deleted
Sorry, I didn't see the OP was 3 yrs ago. Apologies.
This thread needs to be closed.

Last edited by easysid (2014-03-07 15:05:20)

Offline

#14 2014-03-07 19:03:40

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Bash Scripting with Conky -- How to implement?

Closing...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB