You are not logged in.

#1 2019-06-06 21:51:12

Anzu
Member
Registered: 2017-02-23
Posts: 5

Low battery notification pop up with dunstify on i3-gaps

Hi ! i have i3-gaps on my laptop and i want to make a notification with dunstify when my battery is low.

So i made a systemd script under /etc/systemd/system/low_battery.service like this:

[Unit]
Description=Send alerts on low battery

[Service]
Type=simple
ExecStart=/bin/bash /home/myUser/.config/i3/low_battery_alert.sh>
Environment="DISPLAY=:0.0" "XAUTHORITY=/home/myUser/.Xauthority">
Restart=always
RestartSec=60

[Install]
WantedBy=multi-user.target

I made low_battery_alert.sh like this:

           
#!/bin/bash

if [ $(cat /sys/class/power_supply/AC0/online) = "0" ] && \
   [ $(cat /sys/class/power_supply/BAT0/energy_now) -lt "4000000" ]; then
       # Display Notification
       if [ $DISPLAY ]; then dunstify -u critical \
       -i battery_low \
       -t 2000 "Battery Critically Low" "Plug in to AC or Suspend immediately"
        # Play Alert Sound
       canberra-gtk-play -f "/usr/share/sounds/deepin/stereo/power-plug.wav"
           fi
fi

low_battery_alert.sh works because when my battery is low i hear the sound of canberra-gtk-play,
but there is no notification pop up and i can't understand why.
If i use same command "dunstify -u critical -i battery_low ..." in a terminal i can see notification on the top of my screen.
So i think is relate to something of DISPLAY variable of systemd. Thanks for any help!

Last edited by Anzu (2019-06-06 23:09:16)

Offline

#2 2019-06-06 22:26:30

2ManyDogs
Forum Fellow
Registered: 2012-01-15
Posts: 4,648

Re: Low battery notification pop up with dunstify on i3-gaps

Please edit your post and use [ code ] tags when posting output.

https://wiki.archlinux.org/index.php/Co … s_and_code
https://bbs.archlinux.org/help.php#bbcode

Offline

#3 2019-06-07 06:49:48

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

Re: Low battery notification pop up with dunstify on i3-gaps

$DBUS_SESSION_BUS_ADDRESS

Offline

#4 2019-06-08 11:21:54

Anzu
Member
Registered: 2017-02-23
Posts: 5

Re: Low battery notification pop up with dunstify on i3-gaps

seth wrote:
$DBUS_SESSION_BUS_ADDRESS

I have tried to search for it on google and found it some solutions, but didn't work for me. So still i have problem to show notification with a daemon

Offline

#5 2019-06-08 12:18:18

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

Re: Low battery notification pop up with dunstify on i3-gaps

tried … some … didn't work … have problem

https://bbs.archlinux.org/viewtopic.php?id=57855

Offline

Board footer

Powered by FluxBB