Change settings when a specific program launches

I would like to create a script that would enable this option when a specific program launches. And if possible, disable this option when the program closes.

Is this possible?
Thank you!

I don’t think it is — not for us mere mortals anyway — but you could always ask around at discuss.kde.org, which is where the KDE developers dwell. :thinking:

Not sure about wayland, but if you’re using X11, you should be able to use setxkbmap to set options. I don’t think there’s one for that though, but AFAIK it should be enough to disable level3 shift.

#!/usr/bin/bash

# off
setxkbmap -option  

# or if you have options you don't want disabled
setxkbmap -option -option grp:lwin_switch,lv5:caps_switch

run-program

# on
setxkbmap -option lv3:ralt_switch

EDIT: I remembered that the first command wasn’t quite right, I’ve now split it into two. More info: It only adds options, unless you have an empty option argument in which case it removes them all, so we need two -option arguments if you want to keep some options.

1 Like

Hi @Razcoina,

I want to do something similar, so I just tested this, and it seems to be working. This is similar to the idea shared by @dmt. I don’t know the command to do this, so here is the psuedo-code:

#!/usr/bin/bash
/command/to/disable/key
/command/to/run/program
/command/to/enable/key

I do not have an idea what the command would be to disable a key in Plasma, but I have absolutely no doubt there is on.

This script works as follows:

  1. It executes /command/to/disable/key to dis able said key;
  2. it then launches the program, /command/to/run/program in this case, but keeps the script running/active since it was launched by the script;
  3. when the GUI app closes, it runs the command to en able the key again, /command/to/enable/key in this pseudo-code.

You can then either mark the script as executable:

chmod u+x /path/to/script

…and execute it directly, or you can execute it:

bash /path/to/script

…directly with bash.

Hope this helps!

Thank you everyone for the replies. I thought this configuration would be just changing a value in some config file. I think I might try my luck at the kde forum, suggested by @Aragorn

As for the suggestion given by @dmt is there a list of options for those switches?

Thank you everyone!

Of course there is. :smiley:

I did mean to include it at one point, but clearly that didn’t happen.

localectl list-x11-keymap-options

https://wiki.archlinux.org/title/Xorg/Keyboard_configuration#Setting_keyboard_layout

1 Like