I'm using Lubuntu 19.04 with LXQt

I'm trying to remap the Caps-Lock and Escape keys. I have found the commands I needed to make that happen and I've made an executable script for them. If I run the script, it works; the problem is that I can't find the way to run the script on boot.

Here is my script, which is located in /usr/local/bin/:


setxkbmap -option caps:none
xmodmap -e "keycode 9 = Caps_Lock"
xmodmap -e "keycode 66 = Escape"

Now, I have already tried with a cron job, running:

crontab -e

@reboot /usr/local/bin/my_script

I also tried running the previous command as sudo, with:

sudo crontab -e

or for my specific user:`

sudo crontab -u user -e

I gave up using cron and tried adding the specific commands to /etc/init.d/rc.local and making the file executable using chmod, as I had to create the file.

Also, I tried adding it on /etc/rc.local.

What can I do to make this work?

  • it is possible to make all your 3 commands work in a easy way.. can you clarify.. you want caps to do nothing with your first command and what about other two? – PRATAP Sep 29 at 8:30
  • @PRATAP I want it to do nothing, then I make Esc be Caps And then Caps be Esc, should have worked with only the last two commands but it did not, somehow it works when I run the first one. – raarv Sep 29 at 8:45
  • 0k your goal is to swap caps ans esc rite?? – PRATAP Sep 29 at 8:50
  • well, yeah, my script already solves that but I don't want to have to run it every time I turn on the pc – raarv Sep 29 at 8:53
  • 1
    You need to provide more information. What do you mean that the script doesn't work? Does it not execute? Does it execute and do nothing? In either any cronjob or rc.local script you are testing, you should do two things (these are prime tools for any debug. Put "set -x" (no quotes) as first line after shell start line so it will show each command as executed then when executing the script use "fullscriptpath >nohup.out 2>&1" to make otput and error go to nohup.out. If you want to have it run by root, put it in root's home dir with proper ownership/permissions. Remove "set -x" after debugging. – jpezz Sep 29 at 10:07

create a file named swap.desktop or any name with .desktop extension in the directory /etc/xdg/autostart/ with the below content and reboot to see the change..

[Desktop Entry]
Exec=setxkbmap -option caps:swapescape

Tested in Lubuntu 18.04

Further Reading:

  • 1
    @dessert you are right, I run LXQt. Will edit the post to clarify – raarv Sep 29 at 9:10
  • This solves my particular problem, thank you. If I wanted to run a script on boot, this is not the way to do that, right? any idea on how to go about that? I should start debugging some test with cronjob and see why those don't work. – raarv Sep 29 at 10:38
  • @PRATAP even after login, for example if I want to change the iptables of the user, should I do that with a .desktop file? or a cronjob would be better. My question is about best practices. – raarv Sep 29 at 10:58
  • 1
    but scripts in /etc/xdg/autostart/ are executed once the user logs in.. – PRATAP Sep 29 at 11:00

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.