Skip to content

Instantly share code, notes, and snippets.

@apraga
Created December 21, 2012 13:40

Revisions

  1. apraga created this gist Dec 21, 2012.
    27 changes: 27 additions & 0 deletions notify.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/bin/bash
    # popup a small notification with 'notify-send'
    dis=`formail -X From: -X Subject:`
    from=`echo "$dis" | formail -X From:`
    sub=`echo "$dis" | formail -X Subject:`

    # tweaks < > are special
    from=${from//</\(}
    from=${from//>/\)}
    from=${from//&/\.}
    sub=${sub//</\(}
    sub=${sub//>/\)}
    sub=${sub//&/\.}

    sub=${sub:0:75}
    from=${from:0:75}
    TM=2000

    pids=`pgrep -u alex gnome-panel`
    for pid in $pids; do
    # find DBUS session bus for this session
    DBUS_SESSION_BUS_ADDRESS=`grep -z DBUS_SESSION_BUS_ADDRESS \
    /proc/$pid/environ | sed -e 's/DBUS_SESSION_BUS_ADDRESS=//'`
    # use it
    DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS \
    /usr/bin/notify-send -u normal -t $TM "$sub" "$from"
    done