You are not logged in.

#1 2017-10-21 17:31:06

cyanpencil
Member
Registered: 2016-10-02
Posts: 1

Unable to display notification on charger plug in

Hi,
I'm having a very hard time displaying a notification when my laptop charger is plugged in or out.

Those are the udev rules I inserted:

KERNEL=="AC", SUBSYSTEM=="power_supply", ATTR{online}=="1", RUN+="/home/luca/scripts/charger_udev.sh true"
KERNEL=="AC", SUBSYSTEM=="power_supply", ATTR{online}=="0", RUN+="/home/luca/scripts/charger_udev.sh false"

And this is the charger_udev.sh script:

#!/bin/bash

export DISPLAY=:0 
export XAUTHORITY=/home/luca/.Xauthority

if [[ $1 == "true" ]]; then
    su luca -c 'DISPLAY=:0 notify-send "Charger plugged in!"'
else
    su luca -c 'DISPLAY=:0 notify-send "Charger plugged off!"'
fi

...and it does not work.

It's very strange, however. If I run

 sudo charger_udev.sh true 

it does not work; if I first login to root, and then call the script like this

 su; charger_udev.sh true 

it works!

It's a whole afternoon that I wasted on this; I've tried also using things like xuserrun and sux, but to no avail. Also, the more things I read about how the X server works, the less I actually understand it.
Please someone help me, I am going crazy.

Offline

#2 2017-10-21 18:52:49

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,869

Re: Unable to display notification on charger plug in

You lack the $DBUS_SESSION_BUS_ADDRESS (notify-send operates on dbus), adapt https://gist.githubusercontent.com/Alad … tfile1.txt

Edit: you should btw. rather set the environment by calling

su -c 'env FOO=BAR notify-send blubb' - luca

and be careful with the "!", better put that into single quotes.

Last edited by seth (2017-10-21 18:59:04)

Offline

Board footer

Powered by FluxBB