Saturday, March 22, 2014

Conky calendar with month, year, current day of week title, days of week past title, days yet to come title, current day, days past, days yet to come all individually colorable

Summary: Conky calendar with month, year, days already past week heading, current day of week heading, days yet to come week heading, days past, current day,   and days yet to come with each able to have and individual color.   Also month and year can be positioned to your liking using conky's align, voffset and offset commands.

I accidentally found out that conky reloads it's config file at midnight (perhaps at other times as well) so those of us that were using the execpi to make sure our calendars updated when the day changed can save a few electrons by going to execp as I have done below.

Known issues: This Conky calendar uses the cal command.  On my Debian system (now deceased, trying out Arch now) as well as my Ubuntu 13.10 system the cal command must be issued as cal -h.

So this line:
${execp TODAY=`date +%_d`; cal | tail -n+2 | sed \

Must be changed to:
${execp TODAY=`date +%_d`; cal -h | tail -n+2 | sed \

I believe this is because Debian's cal is actually a link to  BSD's ncal.

On my Arch system I found that using the infinality font packages caused conky to render fonts poorly (excessive vertical spacing and clipping part of characters at the bottom of the conky window)

I noticed that a font has to be defined in the conky config or the numbers of the month do not align correctly.  Be sure to use a monospaced font.

History: My Conky/sed script was inspired by the work of Seth Just.

Simple example of calendar:
Uniquely colorized elements

I think the conky code below is a good starting point to mess around with your preferred color scheme by changing the values of color1-color8.  Once you get that sorted you can stick it in your existing conky or build it out as its own conky as I did in the next example.

alignment top_right
color1 burlywood1 #Month color
color2 burlywood4 #Year  color
color3 darkgoldenrod4 #Weekdays lived color
color4 cornsilk #Current weekday color
color5 darkgoldenrod1 #Weekdays yet to come color
color6 darkorange3 #Days of month lived color
color7 firebrick2 #Current day color
color8 darkorange #Days yet to come color
double_buffer true
use_xft yes
xftfont Droid Sans Mono Slashed:size=12
own_window yes
own_window_argb_visual yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
own_window_transparent yes

TEXT
##################
##   CALENDAR   ##
##################
${alignc}${color1}${time %B} ${color2}${time %Y}
${execp TODAY=`date +%_d`; cal | tail -n+2 | sed \
-e '1 s:.*:\${color3}&\${color6}:' \
-e '1 s:'"$(date +%a |cut -c 1-2)"':\${color4}&\${color5}:' \
-e '0,/'"$TODAY"'/{s/'"$TODAY"'/\${color7}'"$TODAY"'\${color8}/}'}
# 1st -e = days of week, 2nd = current day of week,
# 3rd = current day of month

My personalized calendar
I saved the code below in ~/.conky/conkyrc_cal and run it with:
conky -c ~/.conky/conkyrc_cal

PS.  The mouse and sticky keys indicators require xkbset to be installed, the clock requires the font LCDMono which is located here.

alignment top_right
color1 ffe3a0 #Month color
color2 ffe3a0 #Year  color
color3 7A3900 #Weekdays lived color
color4 ff8a00 #Current weekday color
color5 ffe3a0 #Weekdays yet to come color
color6 7A3900 #Days of month lived color
color7 ff8a00 #Current day color
color8 ffe3a0 #Days yet to come color
color9 ffe3a0 #Sentence color
# count of week and day count of year within sentence is set to color7
double_buffer true
use_xft yes
xftfont DejaVu Sans Mono:size=23
maximum_width 385 # This will have to be adjusted for font size
gap_x 20 
gap_y 15
own_window yes
own_window_argb_visual yes
own_window_hints undecorate,sticky,skip_taskbar,skip_pager,below
own_window_transparent yes

TEXT
##################
##     TIME     ##
##################
${font LCD2:bold:size=75}${alignr 8}${color7}${time %k}${voffset -20}:${voffset 20}${time %M}${font}
######################
# Capslock + Numlock #
######################
${color1}${voffset -89}${if_match "${exec xset q | grep LED | awk '{ print $10 }' | cut -c8}" == "0"}a ↑${else}${if_match "${exec xset q | grep LED | awk '{ print $10 }' | cut -c8}" == "1"}${color7}${blink A}${color1} ↑${else}${if_match "${exec xset q | grep LED | awk '{ print $10 }' | cut -c8}" == "2"}a ${color7}1${else}${if_match "${exec xset q | grep LED | awk '{ print $10 }' | cut -c8}" == "3"}${color7}${blink A} 1${endif}${endif}${endif}${endif}
########################
# Mouse-Keys indicator #
########################
${font :size=12}${voffset -20}${color3}${if_match "${exec xkbset q | grep "Mouse-Keys =" | awk '{print $3}'}" == "Off"}mouse keys${else}${color1}Mouse Keys${endif}
#########################
# Sticky-Keys indicator #
#########################
${color3}${if_match "${exec xkbset q | grep "Sticky-Keys =" | awk '{print $3}'}" == "Off"}sticky keys${else}${color1}Sticky Keys${endif}
###########################
# Latch to Lock indicator #
###########################
${color3}${if_match "${exec xkbset q | grep "Latch to Lock Mask =" | awk '{print $6}'}" == "Off"}mod keys free${else}${color1}Mod Keys Locked${endif}
${color ffe3a0}${hr 2}
##################
##   CALENDAR   ##
##################
${font}${voffset -8}${color1}${time %B}${voffset -5}${font :size=45}${alignr}${color2}${time %Y}
${voffset -71}${font :size=12}${alignr}${color9}week ${color7}${time %U}${color9} and day ${color7}${time %j}${color9} of:                               ${font}
${voffset -10}${execp TODAY=`date +%_d`; cal | tail -n+2 | sed \
-e '1 s:.*:\${color3}&\${color6}:' \
-e '1 s:'"$(date +%a |cut -c 1-2)"':\${color4}&\${color5}:' \
-e '0,/'"$TODAY"'/{s/'"$TODAY"'/\${color7}'"$TODAY"'\${color8}/}'}
# 1st -e = days of week, 2nd = current day of week,
# 3rd = current day of month

No comments:

Post a Comment