Ninja Nichols

The discipline of programming

Re-enable screen brightness Fn keys

My Fn brightness suddenly stopped working on my Thinkpad T510. I traced the problem back to the Nvidia section of my xorg.conf file. After the following small edit, the brightness keys worked again.

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
    Option         "RegistryDwords" "EnableBrightnessControl=1"
EndSection

Export high resolution images from PowerPoint

PowerPoint makes it easy to produce professional looking graphics quickly. Sometimes I need to export high quality versions of those slides. By default, PowerPoint limits exports to a resolution of 96 DPI (by comparison, many printers use 300 DPI). However, it is possible to change the default DPI by creating a registry entry.

For Office 2007, browser to
HKEY_CURRENT_USERSoftwareMicrosoftOffice12.0PowerPointOptions

And create a new DWORD value called ExportBitmapResolution. Finally set the value to the DPI you want, e.g., 300.

Now you can export high quality slides by saving them as images.

Instructions for Office 2003 and a list of DPI values and their corresponding image sizes is available at http://support.microsoft.com/kb/827745

Get VIM to use 256-bit color theme

All this time I’ve been stuck using vim in 8-bit color because I thought my terminal emulator couldn’t support any higher. Turns out all I needed to do was let VIM know that I wanted pretty colors.

Step 1: Make sure you have a VIM color scheme that supports 256 color. I like the wombat256 theme.

Step 2: Tell VIM that you want 256 color by adding this line to your ~/.vimrc file:

set t_Co = 256

Step 3 (optional): Depending on your terminal emulator, you may need to also add this line to your ~/.bashrc file:

export TERM="xterm-256color"

Multiple copies of program in “Open With” dialog

Why are there 20 copies of Photoshop?!

Sometimes duplicate copies of the same program seem to mysteriously show up in the “Open With” dialog. The problem seems to be worse for Windows programs installed with Wine.

The reason there are so many duplicate entries in the “Open With” dialog is due to the way file associates are handled in Wine. Every time a new program is installed in Windows, it has the opportunity to register itself as the handler program for a particular file type. This behavior is also present in Wine.

Each file handler is stored as a .desktop file in ~/.local/share/applications.

Sometimes though, Wine will create a new entry for each and every file type associated with a program. Take MS Excel for example, I have a distinct entry for .xls, .xlsx, .xlsm, .xltm, and .xlsb. These are just for Microsoft’s own variants of their Excel spreadsheet format and each one creates a new entry in the Open With dialog!

At this point, there are two options.

  1. Try to combine several entries together by allowing each one to handle several file types. This is accomplished by editing the “MimeType=” line in the .desktop file. The general format is “MimeType=catagory1/type1; catagory2/type2;” where “catagory1/type1” is something like “text/csv”.
  2. The above method seemed like too much work, so I opted for the second choice. Copy all the file type entries that you don’t need to another directory. I moved all but the essential entires to ~/.local/share/applications-old.

After a little cleaning up my “Open With” dialog looks much better.

My New OpenBox Desktop

OpenBox is a minimalistic desktop window manager which can be run with or instead of Gnome or KDE. The whole environment is very customizable with nearly everything being controlled by a few scripts and XML documents.

Wallpaper: Arch gray
Icons: Elegant-AwOken (part of Elegant Gnome Pack)
OpenBox window decoration: 1977 OpenBox
GTK theme: Elegant GTK
Vim theme: wombat
Conky: .conkyrc plus power consumption script
Tint2: .tint2rc

Controlling Banshee and RadioTray via DBus

I recently began using OpenBox as my window manager in Linux. One issue I ran into was that my media players were unable to automatically bind to the global media hotkeys. My solution was to write a little bash script to control the media players using DBus. Right now I have support for Banshee and RadioTray. VLC support should be fairly easy to add, but I haven’t had the motivation to search for documentation on their DBus interface.

#!/usr/bin/env bash
#
# Controls playback on any running media players.
#
# usage: media-controller <command>
#
# Command:
#   play
#   pause
#   stop
#   next
#   previous
#
# Supported commands by player:
#   banshee
#       play
#       pause
#       stop
#       next
#       previous
#
#   radiotray
#       play
#       pause
#       stop

if [ ! $# -eq 1 ]; then
    ech o "usage: media-controller <command>"
    exit
fi

COMMAND=$1

BANSHEE_PID=`pgrep -x "banshee"`
RADIO_TRAY_PID=`pgrep -x "radiotray"`

if [ $BANSHEE_PID ]; then
    case $COMMAND in
        play)
            dbus-send --session --type="method_call" 
               --dest='org.bansheeproject.Banshee' 
               '/org/bansheeproject/Banshee/PlayerEngine' 
               'org.bansheeproject.Banshee.PlayerEngine.TogglePlaying'
            ;;
        pause)
            dbus-send --session --type="method_call" 
               --dest='org.bansheeproject.Banshee' 
               '/org/bansheeproject/Banshee/PlayerEngine' 
               'org.bansheeproject.Banshee.PlayerEngine.Pause'
            ;;
        stop)
            dbus-send --session --type="method_call" 
               --dest='org.bansheeproject.Banshee' 
               '/org/bansheeproject/Banshee/PlayerEngine' 
               'org.bansheeproject.Banshee.PlayerEngine.Close'
            ;;
        next)
            dbus-send --session --type="method_call" 
                --dest='org.bansheeproject.Banshee' 
                '/org/bansheeproject/Banshee/PlaybackController' 
                'org.bansheeproject.Banshee.PlaybackController.Next' 
                'boolean:false'
            ;;
        previous)
            dbus-send --session --type="method_call" 
                --dest='org.bansheeproject.Banshee' 
                '/org/bansheeproject/Banshee/PlaybackController' 
                'org.bansheeproject.Banshee.PlaybackController.Previous' 
                'boolean:false'
            ;;
        *)
            ech o "Command not supported for this player"
            ;;
    esac
fi
if [ $RADIO_TRAY_PID ]; then
    case $COMMAND in
        play)
            STATUS=`dbus-send --print-reply --session --type="method_call" 
                --dest='net.sourceforge.radiotray' 
                '/net/sourceforge/radiotray' 
                'net.sourceforge.radiotray.getCurrentRadio'`

            CURRENT_SONG=`ech o '$STATUS' | sed 's/.*"(.*)"[^"]*$/1/'`

            dbus-send --session --type="method_call" 
                --dest='net.sourceforge.radiotray' 
                '/net/sourceforge/radiotray' 
                'net.sourceforge.radiotray.playRadio' 
                'string:'$CURRENT_SONG
            ;;
        pause)
            dbus-send --session --type="method_call" 
                --dest='net.sourceforge.radiotray' 
                '/net/sourceforge/radiotray' 
                'net.sourceforge.radiotray.turnOff'
            ;;
        stop)
            dbus-send --session --type="method_call" 
                --dest='net.sourceforge.radiotray' 
                '/net/sourceforge/radiotray' 
                'net.sourceforge.radiotray.turnOff'
            ;;
        *)
            ech o "Command not supported for this player"
            ;;
    esac
fi

Actually getting the desired effect from the media keys required adding the following XML to my ~/.config/openbox/rc.xml file:

    <keybind key="XF86AudioNext">
      <action name="Execute">
        <command>media-controller next</command>
      </action>
    </keybind>
    <keybind key="XF86AudioPlay">
      <action name="Execute">
        <command>media-controller play</command>
      </action>
    </keybind>
    <keybind key="XF86AudioPrev">
      <action name="Execute">
        <command>media-controller previous</command>
      </action>
    </keybind>
    <keybind key="XF86AudioStop">
      <action name="Execute">
        <command>media-controller stop</command>
      </action>
    </keybind>
    <keybind key="XF86AudioPause">
      <action name="Execute">
        <command>media-controller pause</command>
      </action>
    </keybind>

How much power is your laptop using?

Products like Kill-A-Watt show how much power appliances are using. It’s good way to measure your computer’s power consumption — when it’s plugged in. But what if I want to know how much power my laptop is using when I’m not plugged in?

Turns out it’s fairly easy to get battery info. Running cat /proc/acpi/battery/BAT0/state should return the current discharge rate and total battery capacity.

The trouble is that the “current rate” field sometimes switches between mW and mA. I have no idea why this is the case. Oh well, we can easily convert mA to mW with the formula: $latex watts = amps times volts $.

The end result is this conky friendly bash script:

[bash]
#!/usr/bin/env bash
# Print the current power consumption in watts.
# The script pulls the power consumption info
# from /proc/acpi/battery/BAT0/state
#
# Usage: power.sh [battery_num]
#
# Add to conky:
# ${execi 10 ~/conkyscripts/power.sh 0}
#

# Default is BAT0
BATTERY=0
if [ $1 ]; then
BATTERY=$1
fi

# Sometimes the "present rate" is returned in milliwatts,
# but sometimes it is in milliamps. If it’s in milliwatts,
# we just convert to watts and return. Otherwise we
# convert to watts with the formula:
# Watts = Amps * Volts

UNIT=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present rate:" | awk ‘{ print $(NF) }’`

if [ $UNIT == "mW" ]; then
MILLI_WATTS=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present rate:" | awk ‘{ print $(NF-1) }’`
e cho $[ $MILLI_WATTS / 1000 ].$[ ($MILLI_WATTS % 1000) / 100 ]
else
MILLI_AMPS=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present rate:" | awk ‘{ print $(NF-1) }’`
MILLI_VOLTS=`cat /proc/acpi/battery/BAT$BATTERY/state |
grep "present voltage:" | awk ‘{ print $(NF-1) }’`
POWER=$[$MILLI_AMPS * $MILLI_VOLTS]
echo $[ $POWER / 1000000 ].$[ ($POWER % 1000000) / 100000 ]
fi
[/bash]

Replres.rll

Shortly after installing Visual Studio 2010 I started getting a DLL Load Error message informing me that replsync.dll “Cannot not load resource dll: REPLRES.RLL”. The error message seems to pop up whenever I loose or regain my internet connection. The usual Google search didn’t really turn up any thing. I reinstalled Visual Studio, but the error message came back as soon as I restarted.

The replsync.dll file seems to be associated with SQL Server. In my case it’s located in “C:Program FilesMicrosoft SQL Server100COM”. My solution was to rename “replsync.dll” to “replsync.bak.dll”. Perhaps heavy-handed but the message is gone and I can work in peace once again. It’s been two days and I haven’t noticed any ill effects.

Unwanted Shortcut: Shift + Backspace

My laptop recently died and I had to buy a new one. Since I ended up with an extra hard drive, I decided to use the space to install a KDE distro, as I’ve used Gnome pretty much exclusively. I ended up picking kubuntu 10.10 to try. The installation was smooth and polished as expected from Ubuntu, however, shortly after logging in, I was suddenly logged out and sent back to the KDE login screen.

This happened a few more times before I realized that X server was restarting. Some additional trial-and-error lead me to the problem: X server was restarting every time I pressed Shift + Backspace. I’ve head of CTRL + ALT + Backspace restarting X, but Shift + Backspace was new and all too easy to trigger by accident.

The fix is pretty easy though. Open your ~/.Xmodmap file and change this line:
[sourcecode light=”true”]
keycode 22 = BackSpace Terminate_Server BackSpace Terminate_Server
[/sourcecode]
To this:
[sourcecode light=”true”]
keycode 22 = BackSpace BackSpace BackSpace BackSpace
[/sourcecode]