2

I'm having difficulties running a .sh script when I plug in a Bluetooth keyboard.

I'm using the following udev rule:

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="./scripts/icleverkeybindings.sh" 

The script doesn't appear to be activated when I connect my keyboard. I have also tried "./scripts/icleverkeybindings.sh", "/bin/bash /scripts/icleverkeybindings.sh", and "sh /scripts/icleverkeybindings.sh". I don't understand why this script is not activated.

If I instead use the following udev rule

ACTION=="add", SUBSYSTEM=="bluetooth", RUN+="/bin/mkdir /home/joe/tempfolder" 

Then the folder /home/joe/tempfolder is created when I connect the keyboard.

I have saved the rule in /etc/udev/rules.d/50-addicleverkeybindings.sh. The permissions etc. are: -rw-r--r-- 1 joe root 80 Aug 11 19:53 50-addicleverkeyboard.rules.

The script that I'm trying to run is the following:

#!/bin/bash

sleep 1
cheese

remote_id=$(
    xinput list |
    sed -n 's/.*iClever IC-BK06 Keyboard  .*id=\([0-9]*\).*keyboard.*/\1/p'
)
[ "$remote_id" ] || exit

xkbcomp -i $remote_id /scripts/icleverlayout.xkb $DISPLAY

And ls -la gives -rwxr-xr-x 1 joe root 222 Aug 11 20:00 icleverkeybindings.sh.

If I call simply /scripts/icleverkeybindings.sh from the terminal this works fine.

The script changes the key bindings for my keyboard, I added in the pause in case somehow the script was getting called before xinput knew the keyboard was there, and I added in cheese just to make sure that I knew if it was definitely getting called or not.

Can anyone advise me on how to change my rule so that the script is called?

Thank you

EDIT: To clarify, I created a folder /scripts/, so /scripts/icleverkeybindings.sh is the absolute filepath

Jojo
  • 121
  • /scripts/icleverkeybindings.sh is the full path. does 'make sure the executable bit is set' mean 'run chmod +x ' on the script? because I did that – Jojo Aug 11 '19 at 20:33
  • I've converted my previous comment to answer. – Arkadiusz Drabczyk Aug 11 '19 at 20:33
  • @Joe: yes, it means that – Arkadiusz Drabczyk Aug 11 '19 at 20:34
  • It is better to set that configuration within xorg (i dont know much xkbcomp), udev is an alien to the source and target. Like in https://unix.stackexchange.com/a/439528/12209 – user.dz Oct 14 '19 at 10:49