Posts Tagged ‘osd’

Caps/Num/Scroll Lock Notifications

I’ve been waiting over a month to write this post. The reason that it’s taken me so long is because of a bug that the Ubuntu Devs. have refused to accept an a bug. It’s not their fault I guess, I’m sure they have their reasons. Well, that time has finally come for this post to happen!

One of the things that I’ve really liked about Ubuntu is the way that notifications are handled. They use a very stylish pop-up in the upper right corner of the screen. Well, for a long time, people have been calling it “broken” because of a feature that seems to have been simply, taken away. The ability to set a timeout for when it will force the pop-up to disappear. It seems kind of silly to me to remove this feature since it really hinders what a developer can do with the integrated notification system in Ubuntu. You know what, I’ll get back this in a moment…

What I wanted to be able to do is have a notification pop any time I pressed one of the following keys:

  • Caps Lock
  • Num Lock
  • Scroll Lock

Well, someone on the Ubuntu Forum (red_five) came up with a pretty handy little bash script that can do this pretty darn nicely. Well, actually, his was for Caps/Num Lock, I was forced to tweak the script and add Scroll Lock as well as fine tune the text to my liking. There was a draw back to this though. The notifications were taking a crazy long time (10 seconds) for them to finally disappear. So lets say that you quickly press the Caps Lock on and then back off, the notification stays up for about 20 seconds. Now, I know that 20 seconds is not a long time, but it sure seems that way when you’re looking at the notification….try it.

Well this is where I can get back to where I left off earlier. WebUpd8 recently had an article that spoke of someone who re-wrote the Notify-Osd source code re-adding back the functionality that was left out…TIMEOUTS!! So without further ado, here are the steps for setting up Notifications for Caps/Num/Scroll Lock.

Step 1: Replace Notify-Osd (Note that this patch is only available for 9.10 and up)

  • Add the new repository:

sudo add-apt-repository ppa:leolik/leolik

  • Update & Upgrade:

sudo apt-get update && sudo apt-get upgrade

  • Restart Notify-Osd:

pkill notify-osd

Step 2: Setting Up The Bash Script

  • Open gedit
  • Copy & Paste this in to a new file:
#!/bin/bash
icon="/usr/share/icons/gnome/scalable/devices/keyboard.svg"
case $1 in
 'scrl')
 mask=3
 key="Scroll"
 ;;
 'num')
 mask=2
 key="Num"
 ;;
 'caps')
 mask=1
 key="Caps"
 ;;
esac
value=$(xset q | grep "LED mask" | sed -r "s/.*LED mask:\s+[0-9a-fA-F]+([0-9a-fA-F]).*/\1/")
if [ $(( 0x$value & 0x$mask )) == $mask ]
then
 output="$key Lock"
 output2="On"
else
 output="$key Lock"
 output2="Off"
fi
notify-send -i $icon "$output" "$output2" -t 1000
  • Save the file as lock_keys to your desktop
  • Make the new file executable:

  • Move it to your /bin folder:

sudo mv ~/Desktop/lock_keys /bin

Step 3: Setting up the key bindings

  • Open CompizConfig Settings Manager
  • Click on Commands
  • Find three blank lines and enter these in them:
    • lock_keys caps
    • lock_keys num
    • lock_keys scrl
  • Click on the Key Bindings tab
  • Link the corresponding Run Command # with the command from the previous tab
    • Click on Disabled
    • Check Enabled
    • Click Grab Key Combination
    • Press the key
  • Close Settings Manager
  • Test

Advertisements