2

I have a script that remaps my keyboard. It executes as it should on login but doesn't work on resume. The command is xmodmap .Xmodmap or with full path: /usr/bin/xmodmap /home/arash/.Xmodmap.

I've used Ubuntu's startup application process and for resume, I followed this by adding a bash script to /lib/systemd/system-sleep:

#!/bin/sh

case $1/$2 in
  pre/*)
    echo "Going to $2..."
    exit 0
    ;;
  post/*)
    echo "Waking up from $2..."
    /usr/bin/xmodmap /home/arash/.Xmodmap
    ;;
esac

and have made it executable with sudo chmod x+a.

For some reason it doens't work and I can just see the following message in the logs:

/lib/systemd/system-sleep/key_corrector.sh failed with exit status 1.

By searching a bit, I encountered a few similar cases, (like this or this), but none of them provide any help. I'm open to any idea that solves this once for all!

Further info:

  • I'm using Ubuntu 18.04.
  • It used to work for some time. I believe after an autoremove, it broke.
  • I'm almost a noob and appreciate more the most simple answers. Is there any bug in the bash script or the location

UPDATE:

A combination of all the methods out there worked out for me as long as I do not reboot. Still, I'm not sure why it didn't and why it does now. Just for the record, however, this is what I did:

Based on this, I made a services key_corrector.service that contains the following:

[Unit]
Description=Corrects the key hopefully...
After=sleep.target
StopWhenUnneeded=yes

[Service]
Type=oneshot
User=arash
RemainAfterExit=yes
ExecStop=/home/arash/k.sh

[Install]
WantedBy=sleep.target

and activate it by

sudo systemctl enable key_corrector

note that I had to add User to the service as indicated in the last comment of that answer. Also, as stated here one has to make the script (in my case k.sh) executable by:

sudo chmod +x /home/arash/k.sh

finally, in k.sh itself, I had to set the DISPLAY to zero. The full contamination of this bash file is:

#!/bin/sh
DISPLAY=:0.0 ; export DISPLAY
/usr/bin/xmodmap /home/arash/.Xmodmap

Referring to this answer as well, I have used the absolute path of each command.

arash
  • 81

0 Answers0