Reputation: 51
I am able to get this udev rule in 99-monitor-hotplug.rules to trigger:
ACTION=="change", SUBSYSTEM=="drm", ENV{HOTPLUG}=="1",
RUN+="/usr/local/bin/monitor-hotplug.sh"
But I cannot seem to get it to trigger an OpenCV GUI application in the monitor-hotplug.sh script.
I understand fundamentally the udev rule runs as root but no matter what syntax I try I cannot get it to run properly at the user level for running the application (the actual script to run the application works fine).
I have tried in RUN this format:
su - your_X_user_here -c 'export DISPLAY=:0; bash -c "/path/to/script.sh"'
with script:
#!/bin/bash
#sleep 5
date >> /var/log/opencvlog.log
cd ~/Downloads
./displayimage /home/<username>/Pictures/picture.png
>/var/log/application.log
2>&1
Another attempt:
Adding in 99-monitor-hotplug.rules to the current syntax:
ACTION=="change", SUBSYSTEM=="drm", ENV{DISPLAY}=":0",
ENV{XAUTHORITY}="/home/<username>/.Xauthority" ENV{HOTPLUG}=="1",
RUN+="/usr/local/bin/monitor-hotplug.sh"
then in the actual script:
export DISPLAY=:0
export XAUTHORITY=/home/<username>/.Xauthority
cd ~/Downloads
date
./displayimage /home/<username>/Pictures/picture.png
None of this is working, any thoughts on how to get this to work?
Thanks
Upvotes: 1
Views: 852
Reputation: 171
When using display managers like gdm the current X authority file might not be in the user home directory, but in runtime directories like /run
or /var/run
.
You may try something like:
USER=<username>
export XAUTHORITY=$(find /var/run/gdm3/ -type f -path "*${USER}*" 2> /dev/null)
Newer gdm versions seem to put the file in a more generic location:
export XAUTHORITY=$(find /run/user/$(id -u "$USER")/ -name Xauthority 2> /dev/null)
I used this technique to call xrandr to adjust the screen resolution from a udev rule:
https://git.ao2.it/libam7xxx.git/blob/HEAD:/contrib/am7xxx-autodisplay.sh
Upvotes: 0