Score:2

These commands (setxkbmap and xcape) are in .profile but are not being executed on login

ke flag

I have verified that .profile is executed on login.

However, commands involving setxkbap (e.g. setxkbmap -option ctrl:swapcaps) and xcape (e.g. xcape -e 'Control_L=Escape') seem to be ignored.

Since both programs are for keyboard bindings I figured the reasons they are ignored is related. How can I get them to run on login?

Using Ubuntu 22.04 on Xorg (xcape doesn't work on Wayland).

Gunnar Hjalmarsson avatar
uz flag
Probably better to use Tweaks (you may need to install `gnome-tweaks`) to change the keyboard behavior in this respect.
Rosa avatar
ke flag
@GunnarHjalmarsson Unfortunately it is impossible to replicate the behaviour of xcape with gnome-tweaks.
Gunnar Hjalmarsson avatar
uz flag
Maybe that particular combo is not so easy... Another thought is to put those commands in a shell script and [autostart](https://help.ubuntu.com/stable/ubuntu-help/startup-applications.html) that script at login.
Rosa avatar
ke flag
@GunnarHjalmarsson I managed to do it by using startup applications, but I had to run them as a script with a delay of a few seconds (`sleep 10`). If you want to put this in an answer I will mark it as solved to help others. Thanks.
Gunnar Hjalmarsson avatar
uz flag
Great! Please feel free to use it in an own answer. It's perfectly fine to answer your own question. ;)
Score:2
ke flag

This can done with Startup Applications.

Put your commands in a file with a delay command at the top (this is because keyboard bindings need the desktop environment to be loaded before they can be executed):

sleep 10;
setxkbmap ...;
xcape ...;

Save this as keybinds.sh then in Startup Applications click Add and in the popup dialogue, add this in the Command field (just change the location of keybinds script).

/bin/bash -c "sh /home/user/.../keybinds.sh"

When you login, after 10 seconds the script will run.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.