I am trying to launch a GUI app upon plugging in a certain USB device. The udev rule gets triggered, but the app does appear on my screen. Running the script from another TTY makes the app open in my graphical environment. I can also confirm that the rule is getting triggered by appending a date to a file from the rule.
/etc/udev/rules.d/99-betaflight.rules:
SUBSYSTEMS=="usb", ATTR{serial}=="314839673237", RUN+="/usr/bin/su daniel -c '/home/daniel/bin/betaflight-configurator'"
/home/daniel/bin/betaflight-configurator:
#!/bin/bash
export DISPLAY=:1
/opt/betaflight/betaflight-configurator/betaflight-configurator
The way I understand it is that the GUI app has difficulties starting, since it's not starting in the context of the X server. Still, running the code from another tty opens the app perfectly fine.
What can I improve to make the app run upon plugging in my USB device?
RUN+="..."
block withRUN+="echo $(date) > /home/daniel/udev_exec.log"
for instance. (ii) I would actually look at ADDITIONAL filtering on action with ACTION=="add" placed before yourRUN+="..."
block. That would restrict the trigger condition to you plugging-in your serial device. (iii) Also report if"/home/daniel/.Xauthority"
exists in your home directory... --- There are other issues but you can start with that. Please report by editing your OP.