XChat notification and highlighting on phrases instead of single words

I wrote the following xchat plugin after they decided to “fix” the Extra words to highlight feature in XChat 2.8.6

The python plugin can be downloaded here

__module_name__ = 'hilight-phrase'
__module_description__ = 'XChat notification and hilighting on phrases instead of single words'
__module_version__ = '2.0'

import xchat, os, re

CONFFILE = os.environ['HOME'] + '/.xchat2/hilight-phrase.conf'
list=[]

xchat.prnt('%(name)s, version %(version)s' % {'name': __module_name__,  'version': __module_version__})  

def read_list():
    try:
        conf = open(CONFFILE,'r')
    except:
        xchat.prnt(CONFFILE + " currently doesn't exist, creating")
        return None
    lines = conf.readlines()
    for each in lines:
        list.append(re.sub(r'\n','',each))
    conf.close()

def save_list():
    conf = open(CONFFILE,'w')
    for phrase in list:
        conf.write(phrase + '\n')
    conf.close()

def check_msg(word, word_eol, userdata):
    for phrase in list:
        if phrase in word_eol[1].lower():
            xchat.command("gui color 3")
            xchat.emit_print( "Channel Msg Hilight", word[0], word[1] )
            return xchat.EAT_ALL

    return xchat.EAT_NONE

def add_hilight_phrase(word, word_eol, userdata):
    if len(word) == 1:
        return list_hilight_phrase(word, word_eol, userdata)
    phrase = word_eol[1]
    if phrase not in list:
        list.append(phrase)
        xchat.prnt('\x032* "%s" will be hilighted' % phrase)
    else:
        xchat.prnt('\x032* "%s" is already being hilighted' % phrase)
    save_list()
    return xchat.EAT_XCHAT

def list_hilight_phrase(word, word_eol, userdata):
    xchat.prnt('\x032Current hilight-phrase list: %d hilighted.' % len(list))
    for phrase in list:
        xchat.prnt('\x032  -- %s' % phrase)
    xchat.prnt('\x032* End of hilight-phrase list')
    return xchat.EAT_XCHAT

def remove_hilight_phrase(word, word_eol, userdata):
    phrase = word_eol[1]
    if phrase in list:
        list.remove(phrase)
        xchat.prnt('\x032 "%s" has been removed from the hilight list' % phrase)
    else:
        xchat.prnt('\x032 "%s" is not in the hilight list' % phrase)
    save_list()
    return xchat.EAT_XCHAT

read_list()
xchat.hook_command("hilight-add", add_hilight_phrase)
xchat.hook_command("hilight-list", list_hilight_phrase)
xchat.hook_command("hilight-remove", remove_hilight_phrase)
xchat.hook_print("Channel Message", check_msg)

You can use the plugin by either:
1. manually loading the file through the menu (Windows -> Plugins and Scripts) every time you restart xchat
2. copy the hilightphrase.py to your $HOME/.xchat2/ direcory where it will get loaded automatically when xchat is run.

Once loaded, a /hilight-list will list all of the currently active phrases to highlight. A /hilight-add <phrase> where <phrase> is a string will add the specified phrase to the list. As you can probably guess, a /hilight-remove <phrase> where <phrase> is a currently active phrase will remove it from the list.

Feel free to comment and leave suggestions.

Tuesday, May 26th, 2009 Technology No Comments

New theme poll

What do you think of the new theme?

View Results

Loading ... Loading ...
Tuesday, March 10th, 2009 General No Comments

Converting mp3 files to iPhone ringtones in Linux

It should go without saying that with “iPhone” and “Linux” in the same sentence you’ll need a jailbroken phone for this. Use the following commands to dump your mp3 file to WAV then convert it to m4a:

1. mplayer -vo null -vc null -ao pcm:fast:file=file.wav file.mp3
2. faac -b 128 -c 44100 -w file.wav

You’ll end up with a file.m4a file. Once you have the OpenSSH package installed and running on your iPhone you can use the scp command to copy the ringtone to the correct location:

scp file.m4a root@iphone:/Library/Ringtones/file.m4r

The root password by default is “alpine”. As you can see the file will need to be renamed to end in “.m4r” instead of “.m4a” to be used as a ringtone. You’ll now be able to see it listed with the other ringtones under Settings -> Sounds -> Ringtone.

Saturday, February 28th, 2009 Technology 1 Comment

Changing GNOME desktop background based on time of day

This has already been done before, but I wanted to try to do it myself. It turned out a bit more complicated than I thought it would be on Ubuntu 8.10 and Fedora 10 because of the way gconftool-2 now interacts with D-BUS.

First, I created a script that could be used to change in between a set of predefined background images:

#!/bin/bash

case $1 in
1)
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "/home/derrick/wallpaper/Solar_3200x1200_SunRiseTime.png";;
2)
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "/home/derrick/wallpaper/Solar_3200x1200_DayTime.png";;
3)
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "/home/derrick/wallpaper/Solar_3200x1200_SunSetTime.png";;
4)
    gconftool-2 -t str --set /desktop/gnome/background/picture_filename "/home/derrick/wallpaper/Solar_3200x1200_NightTime.png";;
*)
    echo "Usage: bgchange.sh [1|2|3|4]";;
esac

Then, using the solution that allows gconftool-2 to communicate using dbus while being run by cron, I created another script:

#!/bin/bash

# Export the dbus session address on startup so it can be used by cron
touch $HOME/.Xdbus
chmod 600 $HOME/.Xdbus

env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus
echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus

# Export XAUTHORITY value on startup so it can be used by cron
env | grep XAUTHORITY >> $HOME/.Xdbus
echo 'export XAUTHORITY' >> $HOME/.Xdbus

As the post says, I made the script run each time I logged in by selecting System -> Preferences -> Sessions and adding /home/derrick/bin/.make_Xdbus as a Startup program.

Next, I edited by crontab by running ‘crontab -e’ and adding the following jobs:

00 07 * * * . /home/derrick/.Xdbus; /home/derrick/bin/bgchange.sh 1
00 08 * * * . /home/derrick/.Xdbus; /home/derrick/bin/bgchange.sh 2
00 17 * * * . /home/derrick/.Xdbus; /home/derrick/bin/bgchange.sh 3
00 18 * * * . /home/derrick/.Xdbus; /home/derrick/bin/bgchange.sh 4

The /home/derrick/.Xdbus file is created each time I log in after adding the previous script as an entry in Sessions. You can adjust at what time the script changes the background to what picture. If you’re not familiar with crontab syntax you can take a look at the crontab(5) man page using the command ‘man 5 cron’.

Friday, February 27th, 2009 Technology No Comments

Ubuntu Intrepid Ibex (8.10) on a Toshiba Portege M400

I decided to go ahead and do a fresh install of the Intrepid beta and report my results. So far everything but the fingerprint scanner is working.

http://wiki.control-d.com/index.php?title=Ubuntu_Intrepid_Ibex_(8.10)_on_a_Toshiba_Protege_M400

Friday, October 24th, 2008 Technology No Comments

wiki.control-d.com

The following 4 guides have been moved over to my MediaWiki site and updated:

Intro to the ViM Editor
Vim and R
iPhone 1.1.4 and Ubuntu Linux
Ubuntu Hardy Heron (8.04) on a Toshiba Portege M400

http://wiki.control-d.com

I think it makes them much, much easier to read and follow.

Friday, June 13th, 2008 General, Technology 4 Comments

Moving to MediaWiki

Due to the fact that most of my content is guides and that wordpress isn’t properly displaying some of the text, I’m moving my how-tos over to MediaWiki at http://wiki.control-d.com. The other content will stay over here on Wordpress. I’ll be making posts when I add new content to the wiki.

Monday, May 26th, 2008 General, Technology No Comments

Ubuntu Hardy Heron (8.04) on a Toshiba Portege M400

I’ve been working on getting Hardy running on my M400 and have documented my progress here. The page can also be found under my How-Tos.

Tuesday, May 13th, 2008 Technology No Comments

Debian, lighttpd, and logrotate

I noticed that everyday I had a defunct logrotate process on one of my servers running Debian and lighttpd. After some searching I found this bug report that said to make the following changes to my /etc/logrotate.d/lighttpd file:

postrotate
            if [ -f /var/run/lighttpd.pid ]; then \
              if [ -x /usr/sbin/invoke-rc.d ]; then \
                 invoke-rc.d lighttpd force-reload > /dev/null 2>&1; \
              else \
                 /etc/init.d/lighttpd force-reload > /dev/null 2>&1; \
              fi; \
            fi;

Changes are in red. Just add “2>&1″ to the end of each command.

Thursday, March 27th, 2008 Technology No Comments

Ubuntu Gusty (7.10) and Wacom

I upgraded my Toshiba Protege M400 to Gusty and to my surprise the wacom input stopped working. After searching the internet without much success, I notice that there were two wacom devices, /dev/wacom and /dev/input/wacom. Both were symlinks to /dev/ttyS0, which makes sense as the tablet is basically a serial device attached to the notebook. In my /etc/X11/xorg.conf I had the lines

  Option        "Device"        "/dev/wacom"

under the wacom cursor, stylus, and eraser input devices. After changing the lines to

  Option        "Device"        "/dev/input/wacom"

and restarting X, the input started working again. Why? I don’t know, as they both point to /dev/ttyS0.

Hopefully this is helpful to someone out there.

Sunday, December 30th, 2007 Technology No Comments