From mboxrd@z Thu Jan 1 00:00:00 1970 From: wmorgan-sup@masanjin.net (William Morgan) Date: Sat, 05 Jan 2008 10:43:51 -0800 Subject: [sup-talk] how to have an hook play a sound In-Reply-To: <1199552937-sup-9378@clarabella.clarabella> References: <1199552937-sup-9378@clarabella.clarabella> Message-ID: <1199558282-sup-230@south> Excerpts from Giorgio Lando's message of Sat Jan 05 09:11:10 -0800 2008: > Hi again, I do not speak ruby and I am trying to write an > after-poll.rb which plays a sound when there are new messages. No problem. You were just one small character away. > My less absurd try is perhaps: > > if @num>=1 > system "/usr/bin/aplay -q " > end Just remove the '@'. The variable 'num' is what you want; '@num' refers to a different, instance, variable. @num is undefined, so it defaults to 'nil', and that's why the error was about an undefined method on the nil object. (Incidentally, you can use instance variables to save state between successive calls to the same hook. Not useful in this case, but in more complex hooks this is handy.) > With: > > if @num!=0 > system "/usr/bin/aplay -q " > end > > The sound is always player, also when there is no new message polled. This is because nil is not equal to 0 in Ruby, so the conditional is always true. You can also check out the example hooks on the Wiki (http://sup.rubyforge.org/wiki/wiki.pl?Hooks). Feel free to post your masterpiece there when completed. -- William