Hello everyone, I have a problem with calling xmodmap immediately after resume from “suspend” state:

(My English is far from perfect, since I’m not a native speaker)

N.B.: my xmodmap configuration file is called .xmodmaprc or .Xmodmap in my post.

I have the latest version of Antergos dual boot with Windows 10 and I make some adjustments with Antergos for a few days. I have Gnome 3 as Desktop Environment.

My ultimate goal is to redefine pageup as being Home and pagedown as being End, because my keyboard has not a practical physical layout. I want this redefinition of keys to be persistent accross reboot, login/logout, and with resume after suspend/hibernate.
I can already make it work after gnome 3 login and after reboot thanks to startup scripts (configurated with gnome-tweaks) and with writing the xmodmap ~/.Xmodmap command in .xinitrc and .bashrc .

However, since a few days (and associated internet searches) I block on a problem a priori simple: launch xmodmap when the laptop comes back from a suspend/hibernate state.

I had the time to test several methods: (this is my first 2 days attempts)

1° method) I tried with the following bash script without success:

cat /usr/lib/systemd/system-sleep/00-setKeyMap.sh
if ["$ {1}" == "post"]; Then
	#echo "hello - $(date)" > /tmp/john.txt
	export DISPLAY="0.0"
	export XAUTHORITY="/ home / rex / .Xauthority"
	su - [root or rex] -c "
	(DISPLAY=$DISPLAY /usr/bin/xmodmap /home/rex/.xmodmaprc &);
	DISPLAY=$DISPLAY [dbus-launch or exec] gnome-session "

The curious thing is that this script writes things into /tmp/john.txt but the call to xmodmap does not work.
(I do not know if this is the correct method to use, I got many errors and I replaced the exec gnome-session with a dbus-launch gnome-session without really understanding, it seems to me that exec gnome-session should only be located in a .xinitrc).
In this bash script, I also tried to restart the /home/rex/.xinitrc but it crashed my DE, I had to reboot antergos in command line to remove the line /home/rex/.sxinitrc

2° method) user units(.service files):

# cat /home/rex/modmap.sh
sleep 1 && /usr/bin/xmodmap /home/rex/.xmodmaprc &
exec gnome-session

(the .xmodmaprc file that contains the keys redefinitions works, tested with xmodmap .xmodmaprc)

I also have the following [email protected] file:

Description=Fix xmodmap after resume from suspend

ExecStart="/usr/bin/bash /home/rex/modmap.sh"


which I use with:
systemctl [email protected]
or systemctl [email protected]
then systemctl daemon-reload

and finally I trigger suspend with sudo systemctl suspend and look for errors with systemctl status [email protected][root or rex].service
but still many errors unfortunately, probably due to the fact that I indirectly call a bash script that runs an exec gnome-session command that should only be located in .xinitrc, according to arch forums.

knowing that the ultimate goal of these methods is to develop a mechanism similar to this solution found on the internet (by a guy who also had arch):

in the ~ / .xinitrc:

sleep 20 && xmodmap ~ / .xmodmap &
exec gnome-session

=> apparently this .xinitrc allowed him to redefine his keys when launching the DE gnome or X, while I want the same thing but after the return of a “suspend” (which can be triggered by a sudo systemctl suspend).

I thank you for taking the time to read my post and I am open to any help on it
thank you in advance :)


Hello guys,

I still try to solve the same problem:
automagically launch the call to xmodmap (for keyboard remapping) after return from “suspend”

Feedback with systemd technique:

I managed to write a small [email protected] file:

Description=Fix xmodmap after resume from suspend 

ExecStart=/usr/bin/bash -c '/usr/bin/xmodmap /mnt/jmd_hooks/.Xmodmap'
#ExecStartPost=/usr/bin/cat '/mnt/jmd_hooks/testpw' | /usr/bin/sudo -S /bin/bash -lc '/usr/bin/systemctl stop mnt.mount'


that calls a .mount file
(the .mount file mounts the partition / on /mnt so that the configuration file .Xmodmap (which contains key remappings) is available for the .service file) .
cat mnt.mount

Description=Mount root drive in mnt
[email protected]



When I do sudo systemctl start [email protected] everything goes well and xmodmap is executed, when the [email protected] is finished the /mnt is automatically umount.


the resume.service must be made available to all users with systemctl --user --global enable resume.service. Unfortunately, by default under antergos (and under arch in general) the systemctl --user XXX command is disabled.

To activate it, I tried to follow the arch wiki on the basic setup to be able to use systemctl --user “cmd”.
I do not know if I have wrongly defined or forgot to set variables but I broke something in dbus and/or systemd on my partition / with my first installation of archlinux antergos.

At the next boot, I found myself, after a graphical login in my DE gnome 3, with my system that redirects me to the same login screen of the DE (loop on the login screen) and I could not access the gnome desktop.
By starting on the terminal and looking at the journalctl -xe I saw this error mentioned several times, which probably occured at the precise moment I tried to graphically login in gnome: failed to connect to bus api: no such file or directory.

If someone knows intructions (setup to be able to use the command systemctl --user) more explicit than the English archwiki please warn me, I will avoid redoing the manipulation until I know more.
Indeed, reinstallations take time that I do not have at will.

Feedback on the other attempts:

I managed to add lines that were writing to a test file when system resumes from suspend/sleep. Despite my best efforts, even a

DISPLAY=":0.0" ; export DISPLAY
XAUTHORITY="/home/rex/.Xauthority" ; export XAUTHORITY
echo "regis test 77 other cases -> $(date)" | logger
killall xmodmap
/bin/su rex -c "DISPLAY=:0.0 XAUTHORITY=$XAUTHORITY /usr/bin/sleep 1; DISPLAY=:0.0 XAUTHORITY=$XAUTHORITY /usr/bin/xmodmap /home/rex/.Xmodmap" &

in the handler.sh i did not succeed, i also tried variants of this su command without success. If I remember well, I also tried /bin/su - rex -c "..." & and /bin/su rex -c "..." &

It works in a similar way as the previous acpi handler.sh script
I can write to a test file after returning from sleep, but even trying the same su commands mentioned above, I can not run xmodmap in 00-myscript.sh when the system wakes up.

Paths to explore:
It is possible that the command su - [username] opens another session for username in which su executes the xmodmap command that is passed to it as an argument to the -c option. The session that su opens may be different from the gnome-session already opened by the user username before the suspend state.

If so, is there a way to get the id of the session already open by username before going into sleep / suspend, and attach on it at resume to execute the xmodmap command?

Any help would be greatly appreciated,

Thanks in advance and happy new year :)

John D.