Running xmodmap at start-up

Questions about Grub, the liveCD and the installer
Forum rules
Before you post please read how to get help
Post Reply
hwalinga
Level 1
Level 1
Posts: 24
Joined: Wed Oct 11, 2017 6:52 pm

Running xmodmap at start-up

Post by hwalinga »

Whenever I run xmodmap manually it works fine. However I can't get it to work automatically at start-up.

I made a ~/.Xmodmap file and tried creating a ~/.xinitrc and a ~/.xprofile with the following contents

Code: Select all

#!/bin/bash
[[ -f /home/hielke/.Xmodmap  ]] && /usr/bin/xmodmap /home/hielke/.Xmodmap
Did not work.

Next I tried creating a .config/autostart/keys.desktop file with the contents

Code: Select all

[Desktop Entry]
Name=xmodmap
Comment=Apply Xmodmap
Exec=/home/hielke/.keys
Icon=system-run
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true
Did also not work.

Any more suggestions for me to try? Or is this the systemd madness everybody is talking about, and if I want proper control over my system I better look for a systemd free alternative ... ?
User avatar
catweazel
Level 19
Level 19
Posts: 9884
Joined: Fri Oct 12, 2012 9:44 pm
Location: Australian Antarctic Territory

Re: Running xmodmap at start-up

Post by catweazel »

hwalinga wrote:
Mon May 13, 2019 7:33 pm
Any more suggestions for me to try?
Add the command to the end of .profile for a user-specific scope. If you want global scope, you can add a systemd service: viewtopic.php?t=275464
hwalinga wrote: Or is this the systemd madness everybody is talking about, and if I want proper control over my system I better look for a systemd free alternative ... ?
The only madness is that presented by rabid systemd opponents who know they're gibbering but don't know why.
"There is, ultimately, only one truth -- cogito, ergo sum -- everything else is an assumption." - Me, my swansong.
hwalinga
Level 1
Level 1
Posts: 24
Joined: Wed Oct 11, 2017 6:52 pm

Re: Running xmodmap at start-up

Post by hwalinga »

Thanks for your help, but both the .profile and the systemd service did not work for me.

Code: Select all

[Unit]
After=display-manager.service

[Service]
ExecStart=/home/hielke/.keys.sh

[Install]
WantedBy=default.target
My memory might not be that good, but I thought this was a lot easier to do before my system was using systemd.
hwalinga
Level 1
Level 1
Posts: 24
Joined: Wed Oct 11, 2017 6:52 pm

Re: Running xmodmap at start-up

Post by hwalinga »

Add the command to the end of .profile for a user-specific scope. If you want global scope, you can add a systemd service: viewtopic.php?t=275464
Unfortunately it did not work.
Prouflon
Level 1
Level 1
Posts: 1
Joined: Tue Apr 07, 2020 8:39 am

Re: Running xmodmap at start-up

Post by Prouflon »

Hello. After many many tries, I think I finally was able to reliably make xmodmap autostart properly.

The reason why this problem is so unfathomably hard to troubleshoot is that
ADDING "xmodmap $HOME/.Xmodmap" TO ANY OF SCRIPTS MENTIONED ABOVE DOES NOT WORK!
but executing it from the command line works fine.
I have no Idea why this is, but it might have to do with those files being executed too early for xmodmap to properly modify the X server.
Adding a delay naively doesn't help either.


Solution:
---------------------------------------
Add this line to the startup script of your choice (".xprofiles", ".config/xfce4/xinitrc" and the xfce4 application autostart gui worked for me):
bash -c "sleep 5; xmodmap $HOME/.Xmodmap" &
---------------------------------------

The '&' at the end is important because it tells the script to run this command in the background while the session continues starting. Waiting 5 seconds ("sleep 5") worked well for me, but if your computer takes a little more time logging in, it might be required you increase this value.

If you hate bash:
sh -c "sleep 5; xmodmap $HOME/.Xmodmap" &
should work too but I haven't tested this.
bobcatos
Level 1
Level 1
Posts: 1
Joined: Tue Jul 28, 2020 4:38 pm

Re: Running xmodmap at start-up

Post by bobcatos »

Correction on that filename: it should be ".xprofile", not ".xprofiles".
It works on LM 20 using MATE, OpenBox, and IceWM.
Post Reply

Return to “Installation & Boot”