cappind.py

Zenity for appindicators

Tools like zenity and yad can easily make simple scripts completely graphical, by providing many GUI elements easily  accessible by command line.
However, none of them supports ubuntu appindicators (yet).
This little script does just that.

Download

it's in the attachements:
  • cappind.py is the actual tool.
  • gapping.py is a simple zenity based menu creator, it creates basic appindicator shell scripts.
Also, a few example scripts can be found in the examples page.

How to use

The tool takes input from stdin as multiple lines with the format
menu:submenu:subsubmenu:...:entry
an empty entry meaning a separator
The implied menu structure is automatically created (so no need for a hierarchical input, each line specifies the whole path).
When an entry is selected by the user, the whole path is printed to stdout, which must be piped to something that will execute the actual menu actions.

By default, the menu will close when an entry is selected, the -p flag can make the menu persistant, adding a "Quit" element at the end (the suit menu doesnt print anything, it just closes the program (and its stdout :) ).

Theres also the -i option to choose the display icon, this should be the name of an icon from the theme - not a path to an image file, default is "terminal" (cause this is invoked from a script),
and the -l to add a label next to the indicator icon (which i wouldn't recommend since a lot of label indicators would quickly fill the top panel),
And the -t to specify a timeout in seconds (the indicator will disappear after that).

That's it.

Examples

  • Simple menu example, notice how "_" will underline the next character

(cat <<EOF

_Aa
b:1
b:2
c
EOF
) | ./cappind.py --persist | while read s; do
case "$s" in
    _Aa ) echo hello ;;
    b:1 ) echo big ;;
    b:2 ) echo small ;;
    c ) echo world ;;
esac
done
  • same command (yes that was a single shell command) without the --persist
CONT=true
while $CONT; do
case "`(cat <<EOF
_Aa
b:1
b:2
b:
b:q

c
EOF
) | ./cappind.py`" in
    _Aa ) echo hello ;;
    b:1 ) echo big ;;
    b:2 ) echo small ;;
    b:q ) export CONT=false ;;
    c ) echo world ;;
esac
done
  • now for something actually useful, this will show a list of all the servers in ssh config file, and put a nice "quick access"menu that will connect to the selected host with gnome-terminal
cat $HOME/.ssh/config |
    grep "^[Hh]ost\b" |
    sed "s/^[Hh]ost\b\s*//g" |
    sed "s/\_/__/g" |
    ./cappind.py -p |
    sed -u "s/\_\_/_/g" |
    while read s; do
        gnome-terminal -x ssh "$s" &
    done

Todo

  • possibility to add icons to the menu elements ?
  • provide the command to execute in the input line ?
  • a way to add disabled menu entries
Subpages (1): examples
ċ
cappind.py
(4k)
Reda El Khattabi,
Sep 19, 2011, 10:38 AM
ċ
gappind.sh
(1k)
Reda El Khattabi,
Sep 19, 2011, 1:04 PM
Comments