Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a laptop that I take to work. At home, I have an external keyboard so I usually key num-lock on. At work, I want num lock to be off.

Is there a way to 'schedule' num lock on/of behavior? 9am onwards, num lock should be off by default whenever I switch it on. 7pm onwards, it should be on by default.

:edit: Another approach that was suggested in comments was to set the numlock based on existence of an external keyboard. If you have an external keyboard connected, set numlock on. Otherwise set it off.

Any hints how I can accomplish this on linux (ubuntu 12.04)?

share|improve this question
It looks more like you want the NumLock status to depend on presence of external keyboard, not on a specific time... – grawity Oct 1 '12 at 10:48
That sounds like a better idea. Any clue how to do this? – Utkarsh Sinha Oct 1 '12 at 11:12

You can achieve the initial goal with numlockx command. First, make sure it is installed:

sudo apt-get install numlockx

Then follow Adding Program To Session Startup instructions to add the following command:

date +%H|grep -Eq '^(09|1[0-8])$' && numlockx off || numlockx on
share|improve this answer
up vote 0 down vote accepted

Based on the answer from Serge, I was able to come up with something. I wrote a short script:


x=`lsusb | grep PS/2 | wc -l`

if [ $x -eq '1' ]
    numlockx on
    numlockx off

This works for my machine - you might have to modify it a bit to suit yours. But it lists all USB devices connected. If there's a PS/2 connector (I use one), there will be a USB device for it. Based on it's presence, I turn numlock on/off.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .