1

I have some udev rules written to run when I connect certain usb devices. For example, I change pointer velocity for certain mice, and change xmodmaps for particular keyboards.

The scripts work well when connecting the devices when the computer is on, and also work while connecting them while the computer is suspended. However, these udev rules appear not to fire if the device is plugged in before I boot up or log in. Is there a way to make them run on startup?

I'm using (K)ubuntu 13.04. Here are some examples of my udev rules and scripts.

/etc/udev/rules.d/00-teck.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="0e6a", ATTR{idProduct}=="030c", RUN+="/usr/local/bin/TECK_connect"
ACTION=="remove", SUBSYSTEM=="usb", RUN+="/usr/local/bin/TECK_disconnect"

/usr/local/bin/TECK_connect:

#!/usr/bin/env bash

export DISPLAY=:0.0
cp -f /home/sparhawk/HDD/Computer/Xmodmaps/Xmodmap_for_TECK /home/sparhawk/.Xmodmap
sudo -u sparhawk setxkbmap -layout us -variant altgr-intl
sudo -u sparhawk xmodmap /home/sparhawk/.Xmodmap
sudo -u sparhawk pkill xcape
sudo -u sparhawk xcape -e 'Alt_L=Return' && sudo -u sparhawk notify-send "xmodmap" "TECK connected." -i /usr/share/icons/oxygen/48x48/devices/input-keyboard.png --hint=int:transient:1

/etc/udev/rules.d/90-razerwakeup-slowdown.rules:

ACTION=="add", SUBSYSTEM=="usb", ATTRS{idVendor}=="1532", ATTRS{idProduct}=="0016" RUN+="/bin/sh -c 'echo $env{DEVPATH} | grep -q usb./[^/]*/[^/]*/[^/]*$ && echo enabled > /sys$env{DEVPATH}/../power/wakeup; razer_slowdown'"

/usr/local/bin/razer_slowdown:

#!/usr/bin/env bash
# slow down the tracking speed of a razer mouse.
# to check, $ xinput --list-props "Razer Razer DeathAdder"| grep 'Constant Deceleration'
# which was originally 1

scriptproper () {
        sleep 0.5 # perhaps not necessary, but putting it in background is.
        export DISPLAY=:0.0
        sudo -u sparhawk xinput --set-prop "Razer Razer DeathAdder" "Device Accel Constant Deceleration" 3
}

scriptproper &
don_crissti
  • 79,330
  • 30
  • 216
  • 245
Sparhawk
  • 19,561
  • 18
  • 86
  • 152
  • let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/8913/discussion-between-don-crissti-and-sparhawk) – don_crissti May 24 '13 at 11:28
  • @don_crissti New question created: http://unix.stackexchange.com/questions/76959 – Sparhawk May 24 '13 at 11:44
  • 4
    Possible duplicate of [Can I launch a graphical program on another user's desktop as root?](http://unix.stackexchange.com/questions/1596/can-i-launch-a-graphical-program-on-another-users-desktop-as-root) – Gilles 'SO- stop being evil' Feb 26 '16 at 20:40
  • 1
    @Gilles - I don't quite see how this is a duplicate... Sparhawk doesn't want to launch a graphical program on another user's desktop. – don_crissti Feb 26 '16 at 21:35
  • 1
    @don_crissti Hmm, yes, ok, the question here is launching an X program when no X server is running, which is a different. Not that this thread is really helpful on its own, but well, ok, it isn't a duplicate. – Gilles 'SO- stop being evil' Feb 26 '16 at 22:00

1 Answers1

3

No, since the operations you describe all require a running X server. You should consider creating an autostart item for them.

Ignacio Vazquez-Abrams
  • 44,857
  • 7
  • 93
  • 100