0

My entire rc.local file

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
cd ~/xcape && ./xcape -e 'Control_L=Escape'
exit 0

This is supposed to make my caps lock key (which is set to Left control) become an escape key when pressed by itself, and be ctrl when pressed and held.

The command in the rc.local file works fine when I do it on the terminal, but when I boot up my computer, I have to run the command manually because the rc.local file didn't run the command... or it failed.

2 Answers2

3

Avoid the ~ in the script, use your full directory path. Not only is another script interpreter running (dash instead of bash) which doesn't understand the ~ convention, the script is running as root, so even if ~ was understood, it would be the wrong home directory.

ubfan1
  • 17,838
3

When rc.local runs during boot, it runs as root and the environment is restricted.

You should change ~/xcape with /home/yourUser/xcape.

In order to verify your /etc/rc.local script you should use this command:

 sudo service rc.local start
Lety
  • 6,039
  • 2
  • 29
  • 37
  • Considering this post, sudo service rc.local start might be a better way to test than sudo /etc/init.d/rc.local start. – muru Oct 29 '14 at 00:14
  • Hi, Thank you for the response. I did as you recommended, only I was originally using the etc/rc.local file. I changed it to the /etc/init.d/rc.local now, and run sudo service rc.local start and get this error: Unable to connect to X11 display. is $DISPLAY set? – John Curry Oct 29 '14 at 01:12
  • Yes, you need to define $DISPLAY variable and every variables that xcape needs. – Lety Oct 29 '14 at 11:48
  • this worked for me, my rc.local stopped running and I had to sudo systemctl daemon-reload and it worked again – evanjmg Jan 12 '20 at 20:52