1

I have several startup applications:

user@host:~$ ls -l .config/autostart/
. . .
. . . XXX.desktop
. . . YYY.desktop
. . . ZZZ.desktop
. . . setxkbmap.desktop

Among these is a command to disable Caps Lock:

setxkbmap -option caps:none

First, whenever I try to edit any of these startup commands with sleep, they don't seem to work:

sleep 20; setxkbmap -option caps:none

or...

sleep 20 && setxkbmap -option caps:none

And, second, if I remove the sleep command from all startup commands, and then put the Caps Lock disable command at the top of the list, it doesn't work but the others do...

All the commands if run in the terminal, outside of startup applications, work fine, so I'm unsure as to why they don't work on boot.

UPDATE

Based on @Xen2050's answer, I have adapted the methods he suggested into a workable solution. For two of the startup commands I'm using this form:

bash -c "sleep 20; specific_command"

And the the others, I've left as the default startup commands. This is OK, because the machine boots faster, and the Caps Lock disable command is working consistently.

UPDATE 2

Did some additional research, and found out that xkb is probably the best method to disable Caps Lock. Since this question was about startup applications, the accepted answer is valid. But if anyone else ends up here looking for how to disable the Caps Lock key on Ubuntu 16.04, here are some useful tips:.

I went with editing the /usr/share/X11/xkb/symbols/pc, but I think that using user overrides is probably the right way to do it (as @quixotic suggested):

Make Terminal recognize PageUp and PageDown when remapped to different keys

2

1 Answer 1

1

I think .desktop files don't run their Exec= commands in a full/regular shell, so if you want to use multiple commands you need to explicitly run a shell with those commands. For example, these should work:

Exec=sh -c "sleep 5; notify-send test-delay"

Or in your case:

Exec=sh -c "sleep 20; setxkbmap -option caps:none"
5
  • Thanks for the answer and tips... I tried this, and it seems one of my startup commands is working with this method, but with a small exception. I'm using: bash -c "sleep 20; specific_command". However, two other startup commands are reverting back to their "default" that were set upon installation. And, still, the setxkbmap command still is not working if the others use the sleep command (or are executed in the shell, as you've suggested). Commented Feb 24, 2017 at 19:12
  • Hmm, maybe there's some missing settings or the wrong pwd? I tried a .desktop file that echos some commands in bash to a file, and the env is basically the same as in a terminal, but without the TERM= and it runs in ~/.config/autostart while set has different SHELLOPTS & TERM=dumb and a lot of functions aren't there. Could try redirecting stdout & stderr to files if there's any messages that might be helpful, or running the bash -c "stuff" in a terminal has very similar settings & easier to see the output.
    – Xen2050
    Commented Feb 25, 2017 at 21:10
  • 1
    PS that "setxkbmap caps:none" takes some clearing & re-setting footwork to fix capslock again, I don't use setxkbmap regularly so I'm not sure why it wouldn't work. Also did you mean the two other startup commands aren't keeping the new settings / new Exec= line? I thought you mean they were running with default settings, but if the .desktop file's not saving properly try editing it while logged into a different account, even a live iso, etc, some of my settings don't "stay changed" if I'm logged in, especially desktop settings
    – Xen2050
    Commented Feb 25, 2017 at 23:36
  • Thanks @Xen2050 for the extra information. What do you use to disable Caps Lock? I think you are right in general, as after a couple reboots, when I thought things were working, I see my darn Caps Lock key lit... Currently, the only reproducible way I've accomplished something workable is to sleep the setxkbmap caps:none until after the other commands. But this is bad, as the Caps Lock key is functional when I'm logging in (seems to be disabled seconds after logging in, eg, login shell), which is part of the reason why I want it disabled in the first place. Commented Feb 26, 2017 at 17:27
  • My caps lock starts "off" and I don't do anything special to disable it, actually had to read the man page & fiddle around a while to get my caps lock button working again after I pasted the "caps:none" command without really knowing what it would do (it looked safe enough ;-) You might want to run the command earlier, before logging in, this Q's has a few ways to run things at startup askubuntu.com/questions/228304/…
    – Xen2050
    Commented Feb 27, 2017 at 15:17

You must log in to answer this question.

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