Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

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:

#!/bin/bash

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

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

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.