VLC - Turn Numlock off

When you start VLC, then numlock should be off on the keyboard. This is a little bit tricky to get it working as numlock status seems to be related to the logged in user, so you must run the command as your user, not as root. You also need to define the display to change.

The best soluton to do this would be using a VLC Lua extension/script that directly talks to VLC, but this has 2 disadvantages:
- You need to activate your Lua extension manually on every start of VLC.
- It doesn't work for some reason to run external commands using VLC 2.2.1 using os.execute(), it hanged VLC, which makes this a unusable option.

So, instead, here is a crontab solution checking for VLC every minute:

Install numlockx: apt-get install numlockx

Create a file and fill it with this:

# get processes matching vlc
PID=$(ps ax|grep vlc|grep -v grep);

# did we get line
if [[ "$PID" == "" ]]; then

export DISPLAY=':0.0';

# check numlock status
NUMLOCK=$(/usr/bin/numlockx status)
if [[ "$NUMLOCK" == "Numlock is on" ]]; then
        # turn off numlock
        /usr/bin/numlockx off

Save the file somewhere, for example in /var/scripts/vlc-numlock-off.sh

Open /etc/crontab and add the following line:

# check for vlc and turn off numlock if there
* * * * * <your-username-here> /bin/bash /var/scripts/vlc-numlock-off.sh (or the path and the name to the file you created)

This will run every minute, checking for vlc and if so run numlockx to turn it off.

This is a personal note. Last updated: 2017-04-15 00:57:40.








Don't forget to pay my friend a visit too. Joakim