VSIDO Support > Conky

conky and yad - some possibilities


I was working on a yad command (battery notification) and came across this internal yad command (from the yad man page):

--- Code: -----notification
              Display notification icon.
--- End code ---

so the command:

--- Code: ---yad --notification
--- End code ---

sends a notification icon to the system tray. That got me thinking that yad can be used with conky so that conky can send notifications to the system tray - low battery, high cpu, that sort of thing. The goal is to make conky proactive instead of reactive (in the sense that the user needs to be reading it). That way, if a window is covering the conky, a user can still get critical information.

Proof of concept:

My usual conky with fluxbox - I have it docked in the slit so it's always visible, and use "if" to colorize the output for CPU and MEM:

Add a bit of code (snippet)-

--- Code: ---chage:

${offset 8}${if_match ${memperc}<=50}${color7}


${offset 8}${if_match ${memperc}<=50}${color7}${exec yad --notification}
--- End code ---

and sure enough, I get a notification icon (which can be changed in yad) - but the conky itself no longer displays. Same result using execpi, texeci and not docking the conky.

There has to be a way to make this work without a lot of scripting which could get cpu and mem intensive.


I know very little about conky.
If you can make conky write to stdout and format the output to correct format it would work.
yad notification icon can read from standard input but only possible
    commands are icon, tooltip, visible, action, menu and quit.

       Allows commands to be sent to yad in the form  command:args.   Possible
       commands are icon, tooltip, visible, action, menu and quit.

              Set notification icon to ICONNAME.

              Set notification tooltip.

              Set notification icon to visible, invisible or blinking states.

              Specify  the  command  running  when click on the icon.  Special
              string "quit" exit the program.

              Set popup menu for notification icon.  STRING must  be  in  form
              name1[!action1[!icon1]]|name2[!action2[!icon2]]....   Empty name
              add separator to menu.  Separator  character  for  values  (e.g.
              `|')  sets  with  --separator argument.  Separator character for
              menu items (e.g. `!') sets with --item-separator argument.

       quit   Exit the program. Middle click on icon also send quit command.

--- End code ---
Open a terminal window and enter

--- Code: ---yad --notification --image="gtk-help" --listen
--- End code ---
then enter and type in

--- Code: ---tooltip:Hello\nPackrat
--- End code ---
mouse over the icon and you will see a tooltip.
To quit type in

--- Code: ---quit
--- End code ---
This example shows how to use it in a script.
I don't think it can be done without some scripting.


--- Quote from: misko_2083 on May 05, 2017, 11:03:12 PM ---I don't think it can be done without some scripting.

--- End quote ---

That's what I have concluded. I did a bit of searching to see if a lua function could send notifications to the system tray. Nothing.

I think the issue here is that Conky waits for the command to return, which YAD doesn't since it's sitting active in the tray.
You should be able to confirm this by clicking the tray icon ( default is to quit on click ) after which Conky should redraw/show.
If so, then I don't think you can easily work around it.

On the other hand, going the regular bash route, something like this should do the job:

--- Code: ---#!/bin/bash

PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE

exec 3<> $PIPE

function exit() {
    echo "quit" >&3
    rm -f $PIPE
trap exit EXIT

# "--command" is left empty with the purpose of
# disabling "Quit on left click".
# You can still middle click to quit.
yad --notification                  \
    --kill-parent                   \
    --listen                        \
    --image="gtk-help"              \
    --visible=false                 \
    --text="Tooltip text goes here" \
    --command="" <&3 &

function battery_check() {

# BATTERY=$(command to get battery percentage)


while true; do
    if [[ "$BATTERY" -le 10 ]]; then
        echo "icon:battery_empty" >&3
        echo "visible:blink" >&3
        echo "visible:false" >&3
    sleep 10s

--- End code ---

I'm not using a laptop and don't know the command to get battery percentage, so you'll need to fill that in @"battery_check" function.
Also, it won't get anywhere close to hogging the RAM or the CPU, as long as you don't go wild with the "sleep" inside the "while" loop ( low intervals like "sleep 0.1s" ).


--- Quote ---You should be able to confirm this by clicking the tray icon ( default is to quit on click ) after which Conky should redraw/show.
--- End quote ---

Confirmed. By accident though, I was checking the tool tip and quit the yad icon.  :D

Thanks for that script. I'll check it out when I get some time.


[0] Message Index

Go to full version