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

About these ads

19 responses to this post.

  1. Posted by insinache on October 13, 2010 at 1:50 pm

    t’s such a great site. fabulous, extraordinarily intriguing!!!

    Reply

  2. Posted by ciufciagry on November 4, 2010 at 7:43 am

    This is very fine web site, thank you.

    Reply

  3. Great tutorial, thanks

    Reply

  4. I am not getting that keyboard sign but only notification. can you help?

    Reply

  5. Posted by xavier on November 24, 2010 at 4:10 pm

    But, if i no have compiz installed on my system?

    How I execute a script when i press my caps-lock?

    Thanks in advantage

    Reply

  6. [...] done! Thanks to Antoni “Pinguy” for the script tip! Script credits: red_five and excedio (CC) http://www.webupd8.org 2009-2010. | Daily Ubuntu / Linux news and application [...]

    Reply

  7. Posted by kiran on January 12, 2011 at 4:00 pm

    Not working for me on Ubuntu 10.10
    When I run ‘lock_keys caps’ to test, it says notify-send not found !

    Reply

    • Double check that you have libnotify-bin installed. Run this command:

      sudo apt-get -s install libnotify-bin

      This command will not actually install libnotify-bin, but just simulate (-s) the installation to see if there are any errors. Let me know if you encounter any error messages.

      Reply

  8. Posted by Grahame Jrodan on March 1, 2012 at 7:29 am

    The OSD stays on for button press and does not register the next button press until the first one times out. Horrible.
    To solve this I inserted
    killall notify-osd
    at line 2 of the script.
    Works beautifully now

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.