You are not logged in.

#1 2021-08-05 08:28:32

nikinbaidarr
Member
Registered: 2021-05-06
Posts: 101

[SOLVED] Run a shell script when I plugin the device

I like to swap my Esc and CapsLock key on my keybaord and I can achieve that with

setxkbmap -option caps:swapescape

I've also placed it on my xintirc and it works fine when I first turn my computer on. But if I unplug my keyboard(I switch between devices) the effect is gone.

So i want to run that command when I plug in my keyboard

The output of

lsusb

is as follows:

Bus 002 Device 035: ID 258a:002a SINO WEALTH Gaming KB 

I am sure this is the correct device. Because if I unplug that keyboard and run lsusb that line goes missing. I've created a file

/etc/udev/rules.d/00-usb-keyboard.rules

and in there I have

ACTION=="add", SUBSYSTEMS=="usb", ATTR{idVendor}=="258a", ATTR(idProduct}=="002a",
RUN+=" /bin/bash -c 'setxkbmap -option caps:swapescape' "

But it has no affect what so ever. What am I doing wrong here? The file name "00-usb-keyboard.rules" is something that I've randomly put, could that be the problem?

Last edited by nikinbaidarr (2021-08-05 17:42:15)

Offline

#2 2021-08-05 09:25:25

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,989

Re: [SOLVED] Run a shell script when I plugin the device

Wrong user and missing authority and display, https://gist.github.com/AladW/de1c5676d93d05a5a0e1

Also the approach is likely wrong, you can apply layout (options) to match specific devices only, https://wiki.archlinux.org/title/Xorg/K … tion_files

Edit: MatchProduct/MatchVendor - lookup "xinput list" for the product string.

Last edited by seth (2021-08-05 09:27:46)

Offline

#3 2021-08-05 10:53:57

nikinbaidarr
Member
Registered: 2021-05-06
Posts: 101

Re: [SOLVED] Run a shell script when I plugin the device

seth wrote:

Also the approach is likely wrong, you can apply layout (options) to match specific devices only, https://wiki.archlinux.org/title/Xorg/K … tion_files

We were right. My approach was definitely incorrect.

I added the following block in /etx/X11/xorg.conf.d file:

Section "InputClass"
        Identifier "system-keyboard"
        MatchIsKeyboard "on"
        # Option "XkbLayout" "cz,us"
        Option "XkbModel" "pc104"
        # Option "XkbVariant" ",dvorak"
        Option "XkbOptions" "caps:swapescape"
EndSection

Now it is perfectly working. Although could you suggest a way to achieve similar key swapping on the linux terminal as in not just on the xserver?

Offline

#4 2021-08-05 14:11:37

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 75,989

Re: [SOLVED] Run a shell script when I plugin the device

Were we… ;-)

I would assume that you have to derive your own layout in  /usr/share/kbd/keymaps/i386/ - either include or copy an existing one.
And: you'll probably have to go w/ a udev rule if you want that setting to be dynamic (and automatic)

Please always remember to mark resolved threads by editing your initial posts subject - so others will know that there's no task left, but maybe a solution to find.
Thanks.

Offline

#5 2021-08-05 17:41:57

nikinbaidarr
Member
Registered: 2021-05-06
Posts: 101

Re: [SOLVED] Run a shell script when I plugin the device

Hahaha I meant to say You. Your were right lol.

Yeah I will mark this as solved now.

Offline

Board footer

Powered by FluxBB