0

I have a script that remaps escape to caps lock. I normally call the script manually with

xmodmap /home/myusername/.Xmodmap;

.Xmodmap is a file that contains:

remove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_Lock

I want this command to run at boot. What I did is go to /etc/systemd/system and create a file called "startup.service" with this contents:

[Unit]
Description=Startup Applications

[Service]
Type=oneshot
RemainAfterExit=false
ExecStart=/home/myusername/scripts/.qs

[Install]
WantedBy=multi-user.target

.qs is a script with -rwxr-xr-x permissions with contents:

#!/bin/bash
/usr/bin/xmodmap /home/myusername/.Xmodmap; 
rm /home/myusername/stop_time; 
date +%D' '%T > /home/myusername/stop_time

I enable the command by typing systemctl enable startup (not startup.service).

Here's the funny thing. The second and third command work fine on a new boot, the first one does not. It seems to execute the command or skip it somehow. The command works fine when executed in a terminal window. What am I missing here?

1

xmodmap operates on a running Xserver. It's not something you'd run at system boot; it's something you'd run after graphical login, generally as part of a user's initialization script.

Theoretically you might run it through systemd to tweak the keymap on the display manager's Xserver, using After=display-manager.service in your .service file. This will ensure systemd doesn't run it before the graphical login is available. This won't affect a Wayland-based display manager, any Wayland sessions, or a user session that uses a fresh Xserver process, so you probably want to rerun it during user initialization anyway.


(Note the XKB option caps:swapescape does something similar to what your .Xmodmap does, and will function properly in Wayland and other libinput-aware contexts that lack an Xserver for xmodmap to operate on. xmodmap is essentially deprecated, and you should really avoid using it where possible.)

  • And to give a rationale why the proper place is to run it after graphical login: Different users may prefer different keymaps. – dirkt Dec 8 '17 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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