0

Actually I just want to automatically run following single line of code after booting which enables the genius eurkey keyboard setting:

setxkbmap eurkey

Following this guide, whose original example worked without problems, I did the following without success:

# create systemd service file
$ sudo touch /etc/systemd/system/eurkey.service
$ sudo nano /etc/systemd/system/eurkey.service
  [Unit]
  After=network.service

[Service] ExecStart=/usr/local/bin/eurkey.sh

[Install] WantedBy=default.target

create script

$ sudo touch /usr/local/bin/eurkey.sh $ sudo nano /usr/local/bin/eurkey.sh #!/bin/bash setxkbmap eurkey

set permissions

$ sudo chmod 744 /usr/local/bin/eurkey.sh $ sudo chmod 664 /etc/systemd/system/eurkey.service

enable service unit

$ sudo systemctl daemon-reload $ sudo systemctl enable eurkey.service

reboot

$ sudo reboot

However, the code won't execute. What am I missing? Why does it work with the code in the guide and not with my own line of code? I was planning to add an arbitrary number of lines later (which I would call a script). Is this the wrong approach?

A very similar guide I found here on ask ubuntu.

jay.sf
  • 341
  • 1
  • 3
  • 14
  • If you execute systemctl start eurkey.service does it find and execute your scripts? I also notice that the permissions of the service files that I have in /etc/systemd/system/default.target.wants are 777 (as opposed to 664) – Charles Green Mar 28 '21 at 19:25
  • 2
    I don't think you can effectively run setxkbmap command at boot, because this command needs an active X server and there is no X server running at the moment the system boots. You probably need to run this in X session startup programs, not at boot. – raj Mar 28 '21 at 19:31
  • @CharlesGreen When executing this there's no error, so I assume it can at least be found. But it's not getting executed since the keyboard doesn't change. – jay.sf Mar 29 '21 at 05:51
  • @raj Interesting, thanks. – jay.sf Mar 29 '21 at 05:52

2 Answers2

2

If you'd like to start a script when Gnome is starting, look here. Putting an setxkbmap in .bashrc won't help if the X server is not running (yet) and if you're not (manually!) starting a terminal each time after the X server starts. Caveat: I haven't tried either 'solution', because I verified the solution below and it works:

If you edit two files (as superuser - be careful!) on your system, you could have each user configure the layout for themselves and never worry about it again:

sudo nano /usr/share/X11/xkb/rules/evdev.xml

and insert the following just below the variant altgr-intl:

    <variant>
      <configItem>
        <name>eu</name>
        <!-- Keyboard indicator for European layouts -->
        <shortDescription>eu</shortDescription>
        <description>EurKEY (US based layout with European letters)</description>
        <languageList>
          <iso639Id>cat</iso639Id>
          <iso639Id>dan</iso639Id>
          <iso639Id>eng</iso639Id>
          <iso639Id>est</iso639Id>
          <iso639Id>fao</iso639Id>
          <iso639Id>fin</iso639Id>
          <iso639Id>ger</iso639Id>
          <iso639Id>gre</iso639Id>
          <iso639Id>gsw</iso639Id>
          <iso639Id>ita</iso639Id>
          <iso639Id>lav</iso639Id>
          <iso639Id>lit</iso639Id>
          <iso639Id>nld</iso639Id>
          <iso639Id>nor</iso639Id>
          <iso639Id>por</iso639Id>
          <iso639Id>spa</iso639Id>
          <iso639Id>swe</iso639Id>
        </languageList>
      </configItem>
    </variant>

(I took this from /usr/share/X11/rules/evdev.extra.xml and replaced layout with variant. Note that French is missing: you will not find this variant if you choose French (see below).) Next edit:

sudo nano /usr/share/X11/xkb/rules/xorg.lst

and insert one line below altgr-intl:

      eurkey          us: English (US based layout with European letters)

The last thing you need to do is to reconfigure the xkb-data:

sudo dpkg-reconfigure xkb-data

Now, the user will be able to run gnome-control-center (aka 'Settings'), go to 'Region and Language' and add a keyboard layout:

Language selection in gnome-control-center

Choose English (United States) and see this after you scroll down quite a bit:

enter image description here

Choose EurKEY and that user is done, even when the system is shutdown and rebooted. In other words: the setxkbmap eu is no longer necessary!


There might be something wrong with the way EurKEY is integrated. The setxkbmap eu works out-of-the-box on my Ubuntu 20.04, but I cannot find it anywhere in the gnome-control-center (if that's what is meant by "keyboard layout configuration panel" on the EurKEY website).

On their website, there is an eurkey.deb. Looking inside (ar -x eurkey.deb and tar xvf control.tar.gz) we find a postinst script that edits some xml files in /usr/share/X11/xkb/rules. The edits are different from what is distributed but I used it to see how they did it. They're adding a layout called eu, but I don't know how to select the language eu. Then again, I'm no expert.

We did develop an alternative for altgr-intl that suits European languages a bit better and in the process we had to do something similar for the new layout.

Keyboard layouts that suit everyone are hard to make. EurKEY was made in Germany and it shows: the Portugese use a-tilde and o-tilde a lot, but it's not on EurKEY. I like our new altgr-weur better, but I'm biased!

Adriaan
  • 322
  • Wow great hack very nice! I think that was exactly the problem that EurKEY didn=t appear in the gnome-control-center. There was alrfeady a <layout> section in the evdev.xml but no <variant> section of it. After applying your solution I now bizarrely have two entries in the gnome-control-center: EurKey and EurKey (US based...), where only that one without the parentheses finally worked! Your altgr-intl looks great, perhaps I should try it. – jay.sf Mar 30 '21 at 10:05
0

However, the code won't execute. What am I missing?

It does but it does not remain active: what you did likely gets overwritten by what is happening later in the systemd chain. You need to do this as late as possible but as this also will not survive when you switch layouts and you will need to redo this each time you switch keyboards.

You can put

setxkbmap eurkey

at the end of .bashrc doing

vim ~/.bashrc 

to have working method but this also will not survive switching keyboards.

If that is an issue the link you posted has the answer to what needs to be done:

Apply the layout

Run setxkbmap

setxkbmap eurkey

Or choose EurKEY from the keyboard layout configuration panel. EurKEY is made available in the layout lists of the following languages

That last part makes it permanent and also will apply it if you switch keyboards.

Rinzwind
  • 299,756
  • I see! So, 'does not remain active' refers to the missing X server as @raj noted in their comment? I tried to modifiy the ~/.bashrc but eurkey doesn't activate. The reason I want to do this manually is actually that I (still) cannot find the 'EurKEY' entry in the keyboard layout configuration panel. – jay.sf Mar 29 '21 at 06:08