软响铃 ── 把beep换成音乐

很多人千方百计想关掉控制台(或X终端模拟器)的嘀嘀声. 我觉得有提示音不一定是坏事, 但是那个嘀嘀声听起来的确有点烦人. 而且在我的irssi中那个beep提示音实在是太小声了(而且也不好听).

经过一番寻找, 找到了这个softbeep. softbeep可以拦截多个发出beep的动作, 并将其转化成运行任意命令, 包括播放音乐.

softbeep可以拦截这些事件:

  1. 写入tty控制台的bell字符,就是平时所说的'\a'
  2. 基于gtk/gnome的程序对 gdk_bell() 的调用
  3. 基于Xlib的程序对 XBell() 的调用
  4. 基于curses的程序对 beep() 的调用

安装不多述. 启用softbeep很简单, 设置在环境变量 $LD_PRELOAD 中加入/usr/lib/softbeep/libsoftbeep.so, 或者用软件包提供的包装程序:

softbeep foo

softbeep完全是通过环境变量控制的:

SB_REMOVE_BEL 设为yes的话会丢掉TTY控制台的 '\a' 字符.
SB_RUN 事件发生时运行的程序.

如果使用 softbeep foo 的形式启用softbeep, 那么SB_RUN默认为sb-beep, 可以自定义SB_RUN的值, 但记着要用shell脚本包起来. 我为方便直接改了一下 /usr/bin/sb-beep

#!/bin/sh

FILE=/usr/share/sounds/pidgin/alert.wav

# if [ "$1" == "irssi" ] || [ "$1" == "xchat" ] ; then
#       FILE=/usr/share/sounds/email.wav
# fi

# use the player specified in $SB_PLAYER if defined

if [ -z "$SB_PLAYER" ]; then
        exec esdplay $FILE
else
        exec $SB_PLAYER $FILE
fi

从此烦人的嘀嘀声就变成音乐了~...

This entry was posted on 星期六, 6月 30th, 2007 at 10:54 上午 and is filed under Linux. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

没有评论

Be the first to comment on this entry.

Have your say

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
URIs must be fully qualified (eg: http://www.domainname.com) and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.

  1. Welcome ~

    Life is like a box of chocolates,
    you never know
    what you gonna get.


  2. 因为某原因, google blog 暂时停止更新..
    by AutumnCat, 2007-6-12
  3. 最新文章

  4. 最新评论

  5. 分类

  6. 归档