I've got a setup-notebook-keyboard.sh script that I run everytime after logging in because I like my keyboard with the

  • CapsLock -> Esc,
  • CapsLock+Key -> Ctrl+Key


I've tried to set this up before, but wasn't able to.
I think I've tried setting it up in init.d and also with ubuntu "run on startup". I guess both cases didn't work because they are not run on a shell environment or something...

But anyway, I got stuck with running the script every time after startup and after closing the lid of the Notebook. Can somebody help?

Edit: I don't think this is a duplicate of 'how to persistently remap keys in Ubuntu', I have a script which does two things and I'm happy with it since I've been using it since last year, I just wasn't able to get it to run automatically and I have researched and tried it in different ways.

Edit 2: Please remove the duplicate tag. I've tried the suggestion on the question and none of them worked. I've now tried just adding a simple echo "(profanity) (location)" >> ~/file in:

  • ~/.profile
  • ~/.xinitrc
  • ~/.xsession
  • ~/.gnomerc

The machine is just not doing nothing on the files, or I've done something very wrong.

I've tried adding a (profanity).desktop entry in ~/.config/autostart, tried using the full paths, tried /etc/X11/Xsession.d/00_xx file, tried 00 and 100, closing the lid and opening, rebooting, etc.

I test it by checking if the CapsLock key lights up or not when I press it, because after I execute setup-notebook-keyboard.sh it doesn't light up anymore.

Aditional info that may be important: I'm using gnome shell and it's a graphic user interface.

Version: 10:37:34 ~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.4 LTS Release: 16.04 Codename: xenial

Ps.: Now I tried adding echo "(profanity)" >> file on ~/.bashrc, it runs when I open a terminal(and sorry in advance if you thought I was running ubuntu on a terminal in the first place). So... Why is it so hard to just have a script execute after I log in? No wonder I gave up on it 1 year ago x(

  • "didn't work because they are not run on a shell environment or something." ? Try cron's @reboot or read man pm-action
    – waltinator
    Sep 16 '18 at 1:15
  • Welcome to Ask Ubuntu! I’m convinced that Oli’s answer and Stuarts’s answer are perfectly fine to run arbitrary programs/scripts like yours at X.org session start-up. Did you read and try them? If so, why are you dissatisfied with them? (I’m voting to keep your question closed as a duplicate until you give us a convincing rationale against the current duplicate status.) Sep 17 '18 at 14:22
  • Will try both suggestions and get back to you Sep 18 '18 at 11:48

Add a command to run this script in ~/.profile file. It’ll run as user every time you log in.

If you want to execute some command every time you open new tty(for example every time you open new terminal) you can add command to ~/.bashrc file.

  • so, I open my ~/.profile and there it is a setup-notebook-keyboard.sh line at the end of it, for some reason this is there since last year when I tried setting this up and gave up... The script consists of a setxkbmap and a xcape command, wondering if it could be that some service or daemon isn't up yet when it tries to run it? But anyway, not working for me.. Sep 17 '18 at 8:37
  • 1
    Check if your script has na execute permission (chmod+x) and try passing absolute path to that script.
    – Dysproz
    Sep 17 '18 at 18:45
  • You can also try adding ‚hohup’ before command and & after it (it pushes command to the background)
    – Dysproz
    Sep 17 '18 at 18:49
  • script is +x: -rwxr-xr-x 1 buzaga buzaga 78 Dez 17 2017 setup-notebook-keyboard.sh, tried it with full path, verified full path is written correctly. Closed and opened lid, logged in, did not work, added nohup before and after, did not work... Sep 19 '18 at 0:58
  • When you close the lid, you do not log out - just freezes the session.
    – Dysproz
    Sep 19 '18 at 4:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.