You are not logged in.
#!/bin/bash
#
# Custom event script for mcabber
# Plays sounds and shows notifications
#
# robrene
#
# Commands
PLAY="/usr/bin/play -v 0.3 $HOME/.mcabber/message.wav"
NOTIFY="/usr/bin/notify-send -c im.received"
# Username to look for in MUC messages
username=$USER
# Arguments
event=$1
arg1=$2
arg2=$3
filename=$4
echo $event $arg1 $arg2 $filename >> ~/event.txt
if [ $event = "MSG" ]; then
# $arg1 is the type of message
# $arg2 is where the message came from
case "$arg1" in
IN)
# Play sound
$PLAY > /dev/null 2>&1
# Process file (show notification)
if [ -f "$filename" ]; then
$NOTIFY "$arg2" "`cat $filename`"
rm $filename
fi
;;
MUC)
# Process file
filename=$4
if [ -f "$filename" ]; then
# Find mentioning of user
if grep -i $username $filename; then
# Play sound
$PLAY > /dev/null 2>&1
# Show notification
$NOTIFY "$arg2" "`cat $filename`"
fi
rm $filename
fi
;;
OUT)
;;
esac
fi
I'm writing a script for mcabber that is supposed to make a sound and show a notification under certain circumstances. The problem is that the argument that provides the username of the sender of the message ($arg2) always contains an @ symbol. For example alice@jabber.org.
Now, when I run notify-send foo@bar "message body", the notification doesn't show. If I run notify-send "foo@bar" "message body" there is no problem (note the quotes around the title).
As you see, I have quotes around $arg2 in my script. However, the notification still doesn't show! It does show if I run it by hand and provide it with a name that doesn't have an @ symbol, so I'm sure that's the problem. How do I fix this?
Offline
How 'bout \@ or some other escape?
Offline
Try also with ' instead of "
XPS 13 DE 2015 + K*5
"Machines are so stupid that if you tell them to do something perfect, they'll do it"
Offline
Alright, so apparently there was some totally different problem. I tested and tested, and found out that I needed to add > /dev/null 2>&1 to it in order to work. I'm guessing mcabber does something funky otherwise... Anyhow, it all works now. here is the code for anyone interested:
#!/bin/bash
#
# Custom event script for mcabber
# Plays sounds and shows notifications
#
# robrene
#
# Commands
PLAY="/usr/bin/play -v 0.3 $HOME/.mcabber/message.wav"
NOTIFY="/usr/bin/notify-send -c im.received"
# Username to look for in MUC messages
username=$USER
# Arguments
event=$1
arg1=$2
arg2=$3
filename=$4
# Do something
if [ $event = "MSG" ]; then
# $arg1 is the type of message
# $arg2 is where the message came from
case $arg1 in
IN)
# Play sound
$PLAY > /dev/null 2>&1
# Process file (show notification)
if [ -f $filename ]; then
$NOTIFY "$arg2" "`cat $filename`" > /dev/null 2>&1
rm $filename
fi
;;
MUC)
# Process file
if [ -f $filename ]; then
# Find mentioning of user
if grep -i $username $filename; then
# Play sound
$PLAY > /dev/null 2>&1
# Show notification
$NOTIFY "$arg2" "`cat $filename`"
fi
rm $filename
fi
;;
OUT)
;;
esac
fi
Last edited by robrene (2010-05-30 22:21:51)
Offline