You are not logged in.
Pages: 1
I have looked for quite some time now on how to get a pop-up (notify-send) to work from an acpi event / script
For me to understand this (in a simple way (and please correct my logic!)):
For events I pass everything into the handler.sh script (where i can do whatever with the button events)
When I launch the script manualy (passing the button "code" as an argument) It works!, and i get my pop-up message
When I press the actual button, everything works except notify-send
Something beyond my understanding must be happening (maybe something regarding dbus, x11)
I tried:
adding DISPLAY=:0.0
echo $USER returns nothing :S (who does acpi run as?, and can it use the display?)
Someone with a similar error:
https://bugs.launchpad.net/ubuntu/+sour … +bug/92483
sudo /etc/rc.d/acpid restart does fix the issue, but why does it?
It feels sub-optimal having to restart it on every boot
Sorry if my description of this whole thing is lacking, but im new to both acpi, shell scripting, and permissions in general (who is allowed to do what, etc)
thanks in advance
-Julian
When there is nothing left to do. Do nothing.
Offline
Sorry for double posting, but this seemed important:
After i restart the acpid, the command $USER now returns root (which makes sense, since i restarted it as root (On a side note i would like to know how to restart acpid as a user (without using sudo) if possible. This is so that notify-send uses the color theme I have set for the user triggering the acpi event))
I am now wondering about who "owns" acpid when its first launched??
Im guessing it is launched first from:
/etc/rc.conf
DAEMONS=(@network @syslog-ng @acpid netfs @crond dbus wicd)
But I don't know what user this falls under (if any)
Am I even digging at the right place?
Does me backgrounding it have any say? (so many questions )
I thought acpid was to run in the background anyway
When there is nothing left to do. Do nothing.
Offline
A little hackish, but assuming you are only running a single x session, you could try something like this
/bin/su $(ps aux | grep '[x]init /home' | awk '{print $1}' | head -1) --login -c notify-send .....
Online
It's a daemon that gets run a root. So running notify-send as the root user does nothing. The way to get around it is to run the notify-send command as your user with the Substitute User command:
root@computer # su tom -c "echo $USER"
tom
root@computer #
The -c is explained in the man page; it runs a following command as the previously defined user.
The way I actually do this is to call a script in my bin which does the notification. The script is called using:
# su tom -c "/home/tom/bin/myscript"
Offline
I use this:
notify() {
title="$1"
shift 1
body="$*"
for pid in $(pgrep 'awesome'); do
eval $(grep -z ^USER /proc/$pid/environ)
eval export $(grep -z ^DISPLAY /proc/$pid/environ)
eval export $(grep -z ^DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ)
su $USER -c "notify-send \"$title\" \"$body\""
done
}
Replace awesome with your WM or a program that you will run iff you are in X.
Offline
@skunktrader and BaconPie:
I have now tried to use su in my handler.sh and whilst it doesn't solve my initial problem (Still have to restart acpid ) it does solve the problem of getting messages to have the same color theme as the user , so thanks for getting me closer to the solution.
As for not being able to call notify-send using the acpid launched at boot, I am still just as lost
I keep thinking that someone other than root launches rc.conf? (I am so confused about this xD)
info that might be relevant:
I noticed that the volume buttons worked out of the box (gnome), and I'm not sure what "button event manager" It uses but it seems to be unstable (stops working randomly). I would like to replace this with acpid once I find it, but it raised a question "does having 2 of these button event handlers interfere with each other?" (i hope not)
I will now try your solution Stebalien (its awesome to get so many solutions to try! thanks!)
When there is nothing left to do. Do nothing.
Offline
I have a similar problem. I'm trying to lauch a shutdown dialog when I hit the power button. Here is what I have in /etc/acpi/events/power
event=button/power PWRF 00000080 -*
action=su nc -c "sh /home/nc/.scripts/shutdown.sh"
I have also tried whithout the su command, but it's doesn't work as well. If I restart the acpid daemon, it works, but I don't want to restart the daemon everytime I start my WM..
Offline
Please read the wiki before asking, expecially the part about ~/.Xauthority : https://wiki.archlinux.org/index.php/Acpid, and https://wiki.archlinux.org/index.php/Ru … ps_as_root
Last edited by rwd (2011-03-12 18:08:46)
Offline
Again I cannot solve the problem , tried your method Stebalien and checked those links you referred to rwd. The info at the link assumes I am root and want to access another users X. But it seems to me like the first time that acpid is run it is not as root? (this is what i dont get)
what points to this is when I try:
echo $USER > testForUserFile
In a script run by the acpid started from boot I get nothing, the file is blank :S, but when I restart acpid (as root ofc), the testForUserFile contains "root".
I think il go investigate how the pc boots & what processes are run under which users etc.
@nc, do you get something similar? would be comforting to know there are others with the same issue
It seems to me that the best workaround is to add a "restart acpid" statement to some script that launches on every boot
The search continues
When there is nothing left to do. Do nothing.
Offline
Yes, I get the same as you. If I restart acpid, the file contains 'root'.
Offline
Sorry I haven't had the time to look into this further over the last 2 days, and probably wont for another 4 days (due some uni assignments). For now I'm just going to live with it (although it bothers me to leave things undone D:, and will most likely continue afterwards)
(I did take a swift glance at this boot process stuff, and it's quite heavy x(, but eventually... )
So for anyone else who is also experiencing the same issue (@nc) I apologize for my laziness
Though not trying to (directly) dump the responsibility on someone else, I have to say that I'll be willing to try any solution out there! even the strange ones
-Julian
Edit: I spelled laziness as lazyness
Last edited by JulianNymark (2011-03-14 19:04:07)
When there is nothing left to do. Do nothing.
Offline
https://github.com/mgorny/sw-notify-send solves this.
Offline
Another way of doing this (slightly more generic than Stebalien's method):
notify() {
# Usage: notify "title" "description" [options to pass to send-notify"
title="$1"
body="$2"
shift 2
opts="$*"
# Send messages to users listed by the 'users' command, but only once
# Maybe sh has a better way of doing set operations, but this works:
SENT=""
for USER in $(users); do
case $SENT in
"$USER") ;;
*" $USER") ;;
"$USER "*) ;;
*" $USER "*) ;;
# use 'su USER' to send the message
*) SENT="$SENT $USER"; su $USER -c "notify-send $opts \"$title\" \"$body\"" ;;
esac
done
}
Offline
If you want a generic method for obtaining the active username and display for systems using systemd, see xuserrun.
Offline
Pages: 1