LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-29-2005, 06:13 PM   #1
lydgate
Member
 
Registered: Jun 2005
Location: Fullerton, CA
Distribution: Arch 0.7.1 (laptop) / Slack 10.2 (desktop)
Posts: 41

Rep: Reputation: 15
Scripting IM Notification


I use bsflite as my primary AIM client, and I love it. The only problem is that it can't play sounds or anything (afaik). All I want is a sound soon after an IM arrives, one time, and a local nail message that shows who has sent me messages. Here is how I'm currently doing it. I'm sure it's very inefficient, which is why I'm posting here:

Code:
# I always run bsflite through screen -L so this log always exists.
# The reason the last line of the screenlog is important is that if there are no messages,
# the screenlog reads: @:
# if there are messages it reads: @: [screenname] [screenname]
# where screenname is someone who has IMed me.
b=`tail -n 1 ~/.bsflite/screenlog.0`

# This checks if I have the bsflite window open.  I'm sure there is a more efficient way.
# The reason I have to put the switches is because the screen is always running,
# but the following line is the line I use to reattach to screen, so this line will only appear
# if I'm actually looking at the AIM client.
c=`ps -Af|grep "screen -D -r bsflite"|grep -v grep`

# This checks a file that I write to later if a sound has already been played.
# Let me know if there's a better way.
d=`cat ~/.bsflite/ims`

# This checks b and c by length, to see if there are messages,
# and to see if the window is open.
if [ ${#b} -ge 7 -a ${#c} -le 7 ] ; then
# This sets SN to just [screenname] without the @:
        SN=${b:0:${#b}-4}

# If the length of the current messages is longer than the messages written to file,
# set the volume to a reasonable level, and play a sound
# The A and B save the current volume in case I have it higher or lower, so it can
# play the sound and set the volume back to what it was
        if [ ${#d} -lt ${#SN} ] ; then
                A=`amixer sget 'PCM'|tail -n 1|awk '{print $4}'`
                B=`amixer sget 'Headphone'|tail -n 1|awk '{print $4}'`
                amixer sset 'Headphone' 31
                amixer sset 'PCM' 15

                madplay ~/receive.mp3

                amixer sset 'PCM' $A
                amixer sset 'Headphone' $B
        fi

# This was the best way I could find to delete anything containing Messages from mail.
# The reason I do this is because if I get new IMs, I want only a single mail that shows
# where they came from
        echo "delete /Messages" | nail
# Write myself a mail that tells me who has IMed me
        nail -s "Messages from $SN" bkam < "."

# Write who has IMed me to file, so that the sound only plays once
        echo $SN > ~/.bsflite/ims
fi
Anyway, this is my first linux script basically. Oh yeah, I forgot, when I run another script called aim, it also deletes the mail and does echo "" > ~/.bsflite/ims before running the program, so that when i open the client it removes notifications.

The reason I want this to be efficient is because I run it with crontab all the time, so I don't want it using resources. It seems fairly minimal to me, and running this every five minutes is probably less resources than just running gaim, but the faster/more efficient the better. Tips appreciated.
 
Old 11-01-2005, 04:35 AM   #2
lydgate
Member
 
Registered: Jun 2005
Location: Fullerton, CA
Distribution: Arch 0.7.1 (laptop) / Slack 10.2 (desktop)
Posts: 41

Original Poster
Rep: Reputation: 15
I have a hard time believing this is the most efficient way . . . nobody has suggestions?
 
Old 11-01-2005, 11:59 AM   #3
naf
Member
 
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66

Rep: Reputation: 15
I'm only answering because nobody else has. I don't think I'm going to be much help though.

Perhaps look into updating the bsflite program such that a message gets played.
Polling the system will always be costly.
Perhaps a tail -f ~/.bsflite/ims | script would allow continuous execution as entires are added to ims instead of using a cron job.

Good luck.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NOTIFICATION KNotify 19 E.T.Me Slackware 1 05-09-2005 11:21 AM
email notification mbegovic LQ Suggestions & Feedback 6 04-01-2004 12:36 PM
postmaster notification GraemeK Linux - Networking 4 03-05-2004 03:32 AM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 10:16 AM
email notification elainepearl Linux - General 1 01-14-2002 05:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration