Permanently remap a key to an other xubuntu

2

0

I have seen many questions about how to remap a key, but somehow my problem is that it never remaps permanently.

Here is my ~/bootstrap-custom.sh

#!/bin/sh
# remaps Caps Lock to Ctrl
/usr/bin/setxkbmap -option "ctrl:nocaps"

I have added source ~/boostrap-custom.sh to my startup applications.

The mappings work fine.

However:

  • The mapping doesn't load on startup, or is at least overwritten by something that runs after the startup applications.
  • everytime I plug in my keyboard, the mappings seems to be forgotten.

Any way to make the mapping permanent, but keeping the same method (xkbmap) ?

edi9999

Posted 2015-01-08T15:49:13.140

Reputation: 109

Keep your rep, the answer is over on unix and linux

– Foosh – 2015-01-15T20:15:23.630

1You might not want the rep, but I’m pretty sure there’s no way for edi9999 to get it back. – Daniel H – 2015-01-16T05:23:42.647

@Foosh that's not the whole answer to my question, the script gets overwritten on startup too – edi9999 – 2015-01-16T14:38:17.837

@DanielH is right, bounties are non-refundable. Once you finish setting the bounty, there's no way to get that rep back, even if it doesn't result in any answers at all. – a CVn – 2015-01-21T18:02:43.917

Or, in the case with a question I have open, I did more research in the remaining week and answered the question in a way that would earn my bounty if somebody else answered it. Too bad I can’t claim my own bounty. – Daniel H – 2015-01-22T03:59:53.773

Answers

1

This might be only a partial solution (I honestly don't know how it reacts to keyboard unplugging/replugging), but since you already have a script that does what you want, this might be close enough.

On startup, X11 executes several special programs, if they are present on the system. For our purposes, the most interesting is likely ~/.xsession, which is executed after you have logged in through a display manager, which is the normal setup for a graphical environment these days. (It used to be that you normally logged in to a shell and then ran the command startx to start X; if so, you used ~/.xinitrc for the same purpose.)

We can leverage this to execute commands virtually regardless of what display manager (gdm, gdm3, kdm, ...) and desktop environment (GNOME, Xfce, KDE, ...) you are using.

  1. Create a file named .xsession and place it in your home directory.
  2. Add the following to it:
    #!/bin/bash
    /usr/bin/setxkbmap -option "ctrl:nocaps"
  3. Save, and set the file to mode 755 (chmod 755 ~/.xsession)
  4. Log out and back on, or reboot

This should set your keyboard mapping on login. It should also execute late enough that setxkbmap actually works.

If for any reason this fails to work, log in to a text terminal (Ctrl+Alt+F2 for any F2 in [F1..F6] should be your friend) and delete the file by issuing the command rm ~/.xsession.

For reference, here is my ~/.xsession, which with mode 755 drops me into a Xfce4 session (this can serve as a "known good" example):

#!/bin/sh
xscreensaver &
exec xfce4-session

The exec directive at the end replaces the script itself with the given command. Anything that does not exit more or less immediately will need to be backgrounded, hence the &. (I expect setxkbmap to exit almost immediately, hence no backgrounding of it needed.)

a CVn

Posted 2015-01-08T15:49:13.140

Reputation: 26 553

Thanks for answering. Sadly this didn't work out: Here's my results:

➜ ~ ll .xsession -rwxr-xr-x 1 edgar edgar 53 Jan 22 08:03 .xsession ➜ ~ cat .xsession #!/bin/bash /usr/bin/setxkbmap -option "ctrl:nocaps"

However, the keyboard Caps Lock was still doing the same thing – edi9999 – 2015-01-22T07:09:54.950

Ok, it seems to work now, I had an error in my .xsession-errors that was probably causing .xsession not to execute. It works now. Thanks a lot – edi9999 – 2015-01-22T07:20:01.153

0

You could try to put the shell code in your .profile file, OR the more complicated version is that you use XKB. Here is a quick overview.

For complete overview try this arch wiki article.

NefariousOctopus

Posted 2015-01-08T15:49:13.140

Reputation: 133

Putting the shell script in .profile doesn't change anything (still not working after a reboot). I'm already using xkb, so I don't understand why you say that – edi9999 – 2015-01-20T14:10:03.690

0

Apparently this is a bug.

"I use xfce in arch linux and what I do is edit the ~/.config/xfce4/panel/xkb-plugin-##.rc and add a new line or something and it works for some sessions. Another temporary fix may be what #31 suggests.

  1. Set the desired options in the plugin
  2. Copy the ~/.config/xfce4/panel/xkb-plugin-##.rc to some other file e.g. ~/.config/xfce4/panel/goodxkb.rc
  3. Add this command to a startup job:

    sh -c "cp ~/.config/xfce4/panel/goodxkb.rc ~/.config/xfce4/panel/xkb-plugin-##.rc && pkill xkb" (change the ## to your number)

The pkill part is crucial to reload the plugin and its config."

From https://askubuntu.com/questions/66096/how-to-set-up-xfce4-xkb-plugin-to-remember-settings-over-reboots

Meyekem

Posted 2015-01-08T15:49:13.140

Reputation: 59

I don't think they is much in common with my question. The answer t your question iis whe you use the keyboard settings from xubuntu to change the keyboard layout (eg EN,US,FR,...). These options can't be set from the settings. So I don't see how this could help – edi9999 – 2015-01-20T14:40:46.953

-1

Edit /etc/rc.local and add your path of your script. Make sure is executable and it has the #!/bin/bash at the top. Do not reboot your computer shut it down and switch it on again. This should work.

root-expert

Posted 2015-01-08T15:49:13.140

Reputation: 1

Sorry, this doesn't work either. – edi9999 – 2015-01-21T14:56:01.480

Edit /etc/rc.local and add your path of your script. Make sure is executable and it has the #!/bin/bash at the top. – root-expert – 2015-01-21T15:13:51.130

setxkbmap affects the X11 session it is executed within. The man page even gives the name of the tool as setxkbmap - set the keyboard using the X Keyboard Extension. Since /etc/rc.local does not run from within a X session on any Linux distribution I can imagine, nothing run from within /etc/rc.local will affect a running X11. – a CVn – 2015-01-21T17:38:17.883