Dynamic Colour Changes in Conky

Conky is a popular system monitor that I have blogged about before. Its advantages are that it can be whatever you want it to be. You decide what is displayed and the format and so much more.
I’ve got a couple of Conkys on my regular desktop. The main one displays system info and is the one I’m updating today. The other one displays the Now Playing details. It works with both Amarok and Clementine as I switch between them all the time. It only appears when either is in use.
The main Conky includes battery information for both the batteries in my Thinkpad. The information includes the current charge level of each battery, the time remaining on the battery that is currently being used and the status of the batteries i.e. if they are discharging or charging. There is an additional line that shows whether the AC Adapter is attached or not, actually whether it is supplying power or not.
It all has worked well for a while but I wanted the battery information to change colour dependent on the current charge level. A search gave me a number of similar methods of achieving this.
Conky battery status

All these methods had one thing in common, they used Conky’s battery_percent variable but I prefer and use the battery variable. The reason they use the battery_percent variable is simple, battery_percent has a numeric output and therefore the if_match command is easy to use to match the battery charge level. I prefer the battery variable as it outputs status as well as the charge level.
After some experimenting I found a simple solution. I use the battery_percent variable in the if_match statement but use the battery variable for the output. The line from my conkyrc is below. It is all one line in the conkyrc and the second line is the same with BAT) set to BAT1.

$font${color1}Battery 1: $color${if_match ${battery_percent BAT0}<=15}${color7}${blink ${battery BAT0}}${color}${else}${if_match ${battery_percent BAT0}<=25}${color8}${battery BAT0}${else}${if_match ${battery_percent BAT0}>25}${color}${battery BAT0}${endif}${endif}${endif}, ${battery_time BAT0}${color}

The if_match variable looks for 3 different battery charge levels. Above 25% it shows in the regular text colour I use through most of the display. When it reaches 25% the line changes to gold text. A third check looks for a charge of less than 15%. At that point the line of text turns red and starts to blink.

Conky Manager

Conky Manager is a simple way for those who aren’t familiar with Conky to start using it. I’ve mentioned before that I like Conky and have occasionally mentioned how powerful it can be. However making the first steps is the hardest part. It has a very steep learning curve so anything that gets you started is a good idea. That’s where Conky Manager comes in.

Cm-Korora

Conky Manager comes with a number of preformatted Conkys and a search of the internet will locate several more packs that can easily be added to Conky Manager.

The screen shows a list of the installed configurations and below a preview of most. There is an option to recreate the previews. This is handy if you edit any of the designs as I did in the displayed example.

 

Once you’ve selected the design you want there are some options that you can set. These depend on the design but commonly let you choose the screen location and correct network interface and similar personalisations that are unique to your system. You can then start the Conky, set it to autostart whenever you restart the computer. If you want to customise it further you can open it in a text editor.

Conky Manager is available in the repos of most manager distros including Korora and Fedora. You can install it in Korora easily with sudo yum install conky-manager.

If you have ever been curious about Conky and wanted to try it there is no easier way than with Conky Manager, give it a go.

Lots of Little Things

I had one of those days where you don’t do anything much but seem to have a number of small successes. That has been my day.

First I installed Korora 20 Xfce on my netbook. I don’t use the netbook much so it hasn’t been updated for a while. There was no issues, Korora installed without problems.

While checking over the netbook I noticed something that has been happening for a while. My conky is set up to show the current power adapter status, charging, discharging etc. For a couple of versions it has shown ‘no adapter, charging’. Obviously something was wrong but it said charging when it was so it wasn’t a major problem. Looking at the Conky man page I found there is an option for the acpiacadapter variable to specify the subfolder of /sys/class/power_supply that indicates the current state. It looks for AC or ADP1 if the option isn’t used. Fedora and hence Korora uses AC0. Adding that as the option fixed the problem. Easy fix when you take the time to research it.

Second, a minor nuisance is the need to enter my password twice when logging in on my netbook or laptop. I use the same password for login as for the keyring. I found an older post on the Fedora Xfce mailling list that gave the solution. Deleting the leading – from the line

-auth       optional    pam_gnome_keyring.so

in /etc/pam.d/lightdm allows LightDM to open the keyring so it can be used by other applications. Again a simple fix after a bit of research.

I also updated the links on this blog when I noticed that the Korora link was for Kororaa. So I checked all the others and found a couple of dead links and a couple of typos too.

All in all an easy day but some little annoyances fixed.

Amarok Art

I have been using Conky to display the current track information from Amarok. This uses qdbus, the command qdbus org.kde.amarok /Player GetMetadata gives a great deal of information on the track including lyrics, artist, title etc. and the cover art. Search for amarok conky script and you will find lots of examples using this method. It was the cover art that gave me problems recently.

I haven’t used Amarok for a while as I tend to switch between Clementine and Amarok. When I started Amarok conky would show the track details but for many tracks it wouldn’t display the cover art even though it was displayed in Amarok. I searched for a while until I found the problem.

Looking at the output of the qdbus command I saw that sometimes the ‘arturl’ was a file in the music directory. This is where I have put covers that I downloaded manually or that came with the album. I would then use Amarok’s set custom cover screen so Amarok would display them. These lines in the qdbus output show illegal characters like ‘%’ that weren’t part of the filename. When it was a cover that Amarok had downloaded automatically it would be listed as a file in ~/.kde/share/.apps/amarok/. These files worked in Conky.

The answer was simple but time consuming. I used Amarok’s fetch cover option which would then display the custom cover I had previously set. I select it and then it works in Conky. There may be a better way but I haven’t found it yet. Hopefully I will only need to do it for one track from each album.

Conky

Conky is a lightweight system monitor. While that is correct it doesn’t start to explain what Conky can do. Conky can be used to display almost anything you can think of on your Linux desktop. It is simple to use but you can make it as complex as you wish simply by editing the configuration file.

One of the great things is that configuration files from any distro will work on any other distro with little or no change. This means you can copy someone else’s file and use it, adapt it and learn from it. My configuration, like most people’s I guess, is a combination of pieces I found all over the place. See here for a screenshot.

I’ll link to a copy of the file at the bottom of this post along with some links to other info. I’ll go over a few of the parts of my set up that may help someone building their first Conky or maybe looking to improve an existing one. For more information look at the man file for conky with the ‘man conky’ command.

Conky is available for most distros in the standard repos. Most of the temperature readings require lm_sensors (called lm-sensors in some distros) to be installed, configured and running as a service.  There are a couple of other packages needed. I mention them where they are needed.

My Conkyrc File


own_window yes
own_window_transparent yes
own_window_type normal
own_window_hints undecorated,below,sticky,skip_taskbar,skip_pager
own_window_argb_visual yes

#own_window_argb_value=100

These lines do 2 things. First the ‘type’ and ‘hints’ were needed for it to display properly on Xfce. The ‘transparent’ and ‘argb’ lines give transparency.  The line that is commented out (which isn’t in my file) provides a partly transparent background if you prefer it. That does make things easier to read but I prefer full transparency which is the same as setting that line to zero. If you use that line you need to comment out the second line in the section as setting transparency to yes will override the argb value.

<div>

color0 ccaa77
color1 grey
color2 ffff99 #yellow
color3 lightgrey
color4 990033 #dark red
color5 ccaa66 #light gold

You can set colours in the text section but doing it in the layout & options area makes it easier to change colours later. Just one line needs to be edited and the new colour is used right through the display.

In the ‘Text area there is a line for the KDE version. Comment this out if you don’t use KDE.

The next section on the cpu has provision for 4 cores, numbered 0 – 3.  Change this to match the number you have. You could replace the whole lot with a single entry that displays the average for the whole cpu if you prefer.

I’ve commented out the nvidia section as I don’t use the propriatary driver on this system any more and nouveau doesn’t provide this information as far as I can see. If you have any suggestions here please let me know.

The Hard drive section requires hddtemp to be installed and running as a service. You need to edit the /etc/sysconfig/hddtemp file to have the drive in the HDTEMP_OPTIONS= line. I found I couldn’t add 2 drives here. The only way to get it working was to comment the line out. Then all drives are detected.

The last section is for the network details. It uses the ‘if_up’ options to detect which connection I use. This is useful on my laptop where I use Mobile Broadband when I’m not at home and wifi at home. Although this code is for my desktop where I rarely use the mobile broadband. Only for testing and in the rare case of the broadband being down. It requires the following line in the options area at the top.


if_up_strictness address

I find address is the best option here as until an address is found there isn’t a working network connection. See the man file for an explanation and other options.


${if_up ppp0}${font DejaVu Sans:weight=bold:size=10}${color0}MOBILE INTERNET ${font :size=9}(${addr ppp0}) ${hr 2}

$font${color1}Down:$color ${downspeed ppp0}/s${alignr}${color1}Up:$color ${upspeed ppp0}/s
${color0}${downspeedgraph ppp0 25,145 990033 ffbb55} ${alignr}${upspeedgraph ppp0 25,145 990033 ffbb55}
${color1}Downloaded: $color${totaldown ppp0} $alignr ${color1}Uploaded: $color${totalup ppp0}

$else${font DejaVu Sans:weight=bold:size=10}${color0}INTERNET ${font DejaVu Sans:weight=bold:size=9}(${addr em1}) ${hr 2}
$font${color1}Down:$color6 ${downspeed em1}/s${alignr}${color1}Up:$color7 ${upspeed em1}/s
${color0}${downspeedgraph em1 25,145 ffbb55 cc0000} ${alignr}${upspeedgraph em1 25,145 ffbb55 cc0000}

The order is so that it defaults to the home broadband and only shows the Mobile Broadband when it is connected. An ‘endif’ is required too but I have it at the end of the next section so that it is only displayed when I’m at home. If you only use one type of connection you could remove the ‘if_up’, ‘else’ and ‘endif’ as well as one section and edit the remaining section for your connection.

The final part displays the total download for yesterday, the last week and month. It requires vnstat to be installed and running. Unfortunately vnstat is broken in Fedora 16 and hence Kororaa 16, due to systemd I gather. My system is still running 15 so the screenshot shows it working.

That is one of my Conkys. The other one in the screenshot in the last post is for the Amarok track information. You can have as many Conkys running as you want or need.

A good source of further information is the Conky site. There are plenty of sapmle files online a search in your favourite search engine will bring up more than you could ever look at, but here a couple, Conky Galore  and here.

If you are using Conky on Fedora or Kororaa look at this thread on the Fedora forum.

Here is my conkyrc. It is called conkyrc.doc because WordPress doesn’t like text files. Just edit it as required, rename it to .conkyrc and put it in your home directory and start conky. You probably want to have Conky autostart whenever you log in so you don’t have to start it every time.

If you have any questions or any suggestions to improve my setup please add them in the comments. Thanks in advance.

Fedora, Mobile Broadband and Conky

It was over 12 months ago that I blogged about using my Optus mobile broadband with Fedora. I’ve noticed there have been a few searches on that subject recently so I thought it was about time I updated.

With Fedora 11

When I first plugged the 3g modem in it generated a SELinux error and I had to set SELinux to permissive to get it working. That is no longer the case with Fedora 11. Nor does it load the modem as an usb drive. It is recognised as a modem and Network Manager just handles it.

I must add that this seems to apply only to Fedora. I have tried it in Mandriva and Ubuntu derivatives like Gos and only Mint has worked.

This will improve in Fedora 12 with a new feature that will automatically set up the requirements for each provider. Looks like a great feature for those who need to change the default settings.

Working with Conky

Conky is a very useful system monitor. I have often thought of doing a post on Conky but in the interim I’ll just talk about monitoring the Mobile Broadband.

When I first  set up the Mobile Broadband I couldn’t get Conky to report on it. I tried “dmesg | grep usb” and it reported that the modem was using ttyUSB0, ttyUSB1 and ttyUSB2. However none of these would report any activity. Searching around I found that these were redirecting to ppp0. I can’t remember where I found this but it has been consistent across multiple Fedora versions and computers. I can now see the current activity on the Internet connection.

If it is useful here is the code I added to my .conkyrc to get it working

${color0}INTERNET $color(${addr ppp0}) ${color0}${hr 2}$color
${color1}Down:$color  ${downspeed ppp0} KB/s${alignr}${color1}Up:$color ${upspeed ppp0} KB/s
${downspeedgraph ppp0 25,120 color1 color2} ${alignr}${upspeedgraph ppp0 25,120 color1 color2}$color
${color1}Downloaded: $color${totaldown ppp0} $alignr ${color1}Uploaded: $color${totalup ppp0}

Hope that helps.