3

This question already has an answer here:

I have a simple objective: Keep NumLock always on

OS and DE: Linux Mint 17.3 / 18 Cinnamon

I found this:

Keep NumLock always on

So, I created this small script

-rwxr--r-- 1 root      root      47 Apr 15 07:50 keep-numlock-on.sh

with content

#!/bin/bash
xmodmap -e 'keycode 77 = NoSymbol'

and I added it to sudo crontab -e like this

@reboot /home/vlastimil/Development/bash/keep-numlock-on.sh

To my surprise, it does not work on reboot and I have no clue as to why.

It works if I manually call the script.

Any help appretiated.

Further attempts:

I created this file in ~/.config/autostart

-rw-r--r-- 1 vlastimil vlastimil 308 Apr 15 10:00 NumLock.desktop

with content

[Desktop Entry]
Encoding=UTF-8
Name=Keep NumLock always on
GenericName=Keep NumLock always on
Comment=Keep NumLock always on
Exec=/home/vlastimil/Development/bash/keep-numlock-always-on.sh
Icon=
Terminal=true
Type=Application
Categories=
X-GNOME-Autostart-enabled=true
Hidden=false
X-GNOME-Autostart-Delay=0

while renaming the script and changing rights to

-rwxrwxrwx 1 vlastimil vlastimil 47 Apr 15 09:56 keep-numlock-always-on.sh

in order to rule out permission issue.

Well, I don't know what I did wrong, but it still does not work :(

EDIT1:

As for the comments, I changed the contents of the script to:

#!/bin/bash
/usr/bin/numlockx on
DISPLAY=":0" xmodmap -e 'keycode 77 = NoSymbol'

But without luck. This is really annoying to me. Please help and if you solve it, you will be rewarded with 50 points. Thank you.

EDIT2:

sudoedit /etc/X11/xinit/xinitrc

and placed the path to the file in there, still no luck.

. /etc/X11/Xsession
/home/vlastimil/Development/bash/keep-numlock-always-on.sh  

EDIT3:

xmodmap messes up with my keyboard mappings, making it unusable for this purpose.

marked as duplicate by Vlastimil, Community Nov 23 '16 at 11:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • If you manually run the cron job does it work? I am too rusty and do not have the time to look into it but I would guess it has to do with the job setup or privileges – Dylan Apr 15 '16 at 6:52
  • What if you change the content of keep-numlock-on.sh to touch ~/text.txt Does it create the file? I am just checking to see if it is getting called and something is failing inside or if just isnt getting called at boot. I don't man I am sorry. I can't sleep, I shouldnt even be on here right now – Dylan Apr 15 '16 at 6:56
  • 2
    Not the best way to do it. xmodmap works only with X11 running so your cron might try to call it before X11 is running. Use numlockx, either have it called from your login manager or have it in your .config/autostart. For the console, use setleds. You can read: Activating Numlock on Bootup – cylgalad Apr 15 '16 at 7:09
  • Well we eliminated the cron issues. I think cylgalad is on the right track. It is something internal. Narrows it down a lot. Good night and good luck – Dylan Apr 15 '16 at 7:21
  • I'd remove Terminal=true, although it's probably irrelevant in autostart anyway (I'm no expert either, however). – L. Levrel Apr 19 '16 at 15:28
0
+50

I had a similar problem with Xfce: I wanted mouse emulation not to expire.

What worked:

  • launch the script via autostart (like you do)
  • put sleep 5s at the start of the script (increase "5s" if necessary)

Rationale:

If your script works when launched manually, it is not guilty. So the Desktop Environment must be overriding your settings, typically it will apply its configured keyboard map. Hence, launching your script from crontab or .xinitrc will not work. Using the Autostart feature is more reliable, but there is a question: Will the Desktop Environment apply its settings before or after launching your script? That's why sleep is required.

  • I think this is the right answer, since a delay for keymap changes is often needed. OP could also use the X-GNOME-Autostart-Delay=0 line and change 0 to 30, for example. – emk2203 Apr 22 '16 at 11:24
  • @L.Levrel Please see the new thread, where we have solved it finally (I will accept the best answer in 2 days from now): unix.stackexchange.com/questions/301846/… – Vlastimil Nov 23 '16 at 11:12

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