Ubuntu – Lubuntu, running script on boot

19.04bashcronlubuntuscripts

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/:

#!/bin/bash

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?

Best Answer

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]
Name=swapping
Exec=setxkbmap -option caps:swapescape

Tested in Lubuntu 18.04

Further Reading:
http://manpages.ubuntu.com/manpages/bionic/man1/xdg-autostart.1.html
https://specifications.freedesktop.org/autostart-spec/0.5/ar01s02.html

Related Question