#!/bin/bash
#
# A script to tail a file defined by XFCE_MESSENGER_TAILFILE environment
# variable, or /var/log/debug as fallback, and display each line in
# xfce4-messenger-plugin
#
# Author: Auke Kok <sofar@foo-projects.org>
# Distributed under the same terms as xfce4-messenger-plugin
#

[ -z "$XFCE_MESSENGER_TAILFILE" ] && XFCE_MESSENGER_TAILFILE="/var/log/debug"

[ ! -r "$XFCE_MESSENGER_TAILFILE" ] && {
    echo "$XFCE_MESSENGER_TAILFILE does not exist or is not readable. Aborting..."
    exit 1
}

tail -n 1 -f "$XFCE_MESSENGER_TAILFILE" | while read MESSAGE ; do
    dbus-send --dest='org.xfce.Panel.Plugin.Messenger' \
        '/org/xfce/panel/plugin/messenger' \
        'org.xfce.Panel.Plugin.Messenger.Message' \
        string:"$MESSAGE"
done

