You are not logged in.

#1 2012-03-24 21:23:13

davvil
Member
Registered: 2008-05-06
Posts: 165

Simple Tray Icon Tool

I wrote a simple and general tray icon tool, which can be used for general notifications. You can get it from my github.

When started it waits for command on the standard input. Three commands are accepted:

    icon <file>: sets the icon from file
    tooltip <text>: sets the tooltip text
    hide: hides the icon altogether

Application examples:
1. Xmonad layout icons: I tried bmpanel with xmonad (going for a bit more eyecandy than xmobar), but then I loose the status info of xmonad, particulary the layout info (active window and workspaces are shown nicely using ewmh compatibility). With this tool I can define my pretty printer as

ppLayout  = \x -> ("icon " ++ layoutIconPath ++ x ++ ".png")

everything else empty, and pipe the layout to trayIcon.

2. Battery monitor: A bit of parsing of the acpi output

#!/bin/bash

DIR=`dirname $0`

while true; do
    acpiOutput=(`acpi`)
    status=${acpiOutput[2]}
    status=${status:0:-1}
    level=${acpiOutput[3]}
    level=${level:0:-1}
    timeRemaining=${acpiOutput[4]}
    if [[ $status == Charging ]]; then
        icon=$DIR/icons/battery-0.png
    else
        icon=$DIR/icons/battery-${level}.png
    fi
    echo icon $icon
    echo tooltip $status, ${level}%, $timeRemaining
    sleep 30                                                                                                                  
done | trayIcon

3. Mail checking

#!/bin/bash

DIR=`dirname $0`

while sleep 30; do $DIR/imap.py; done | trayIcon

where imap.py is this script adapted for producing the trayIcon commands.

I hope you find it useful and come up with more applications.

PS: If you are intereseted I can share the icons I use.

Offline

#2 2012-03-24 22:26:45

karabaja4
Member
From: Croatia
Registered: 2008-09-14
Posts: 1,001
Website

Re: Simple Tray Icon Tool

echo "tooltip test" | ./trayIcon

doesn't seem to work, what am I doing wrong?

Offline

#3 2012-03-24 23:03:20

davvil
Member
Registered: 2008-05-06
Posts: 165

Re: Simple Tray Icon Tool

On the one hand, if you don't specify an icon nothing will be shown (even if a tooltip is specified). On the other hand, if stdin is closed the program terminates, so using echo is not appropriate. Try this "interactive session":

$ trayIcon
icon /usr/share/icons/hicolor/16x16/apps/firefox.png
tooltip test

Offline

Board footer

Powered by FluxBB