LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Laptop and Netbook (https://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/)
-   -   Help With Docking Station Script, and Udev rules (https://www.linuxquestions.org/questions/linux-laptop-and-netbook-25/help-with-docking-station-script-and-udev-rules-899709/)

jlacroix 08-26-2011 07:46 PM

Help With Docking Station Script, and Udev rules
 
Hello everyone, I am hoping someone can help me with a script as well as udev rules. I am also hoping the solution to this can be helpful others, since docking stations can be a pain.

Anyway, here is a script I wrote after Googling for a while:

Code:

#!/bin/sh
xrandr --current | grep "VGA1 connected "
if [ $? -eq 0 ]; then
        sleep 5s
        xrandr --output LVDS1 --off --output VGA1 --auto
else
        xrandr --output LVDS1 --auto --output VGA1 --off
fi

That script will switch my laptop to the appropriate monitor. If I'm docked, it will go to the external monitor, otherwise it will direct output to the laptops display. I set up a keyboard shortcut in XFCE (ALT+CTRL+=) and whenever I press that, it switches video to the appropriate place. So far, so good.

I also wrote a udev rule, hoping that I can automate this:

Code:

# Rules for docking / undocking

KERNEL=="dock.0", ATTR{docked}=="1", RUN+="/usr/local/bin/dock"
KERNEL=="dock.0", ATTR{docked}=="0", RUN+="/usr/local/bin/dock"

I saved that in /etc/udev/rules.d/81-docking.rules.

Unfortunately, that does not work. I still have to switch the output manually. Any idea what I may have done wrong? I never wrote a udev rule before.

Edit: I totally forgot to mention, this is on a Latitude D630. I'll be setting this type of thing up on a Latitude E6410 when I get it sorted out.

David the H. 08-27-2011 12:08 PM

I have no personal experience with this, but to hazard a guess, I believe udev scripts run as root, which is generally not the user that owns the x session. Perhaps some use of su/sudo would help.

Another possibility may be to use something like halevt instead.

http://www.nongnu.org/halevt/

There are probably better ways to do it though.

Karl Godt 09-07-2011 04:57 PM

udev responds to entries somewhere in the /sys directory .

You could need to have to `echo 'dock' > /sys/path/of/driver/uevent` .

The Puppy boot script /etc/rc.d/rc.sysinit uses `echo 'ADD'` to load the autodetected drivers at boot .

As far as I could observe this , the /sys/.../uevent file gets automatically restored afterwards .

If you add a `cat /sys/.../uevent` before and after the `echo 'ADD' > /sys/.../uevent` you would see no difference .


All times are GMT -5. The time now is 02:13 AM.