I am trying to run this script:

BAT_LEVEL=`acpi -b |grep -Eo "[0-9]+%"|grep -Eo "[0-9]+"`
if [ $BAT_LEVEL -gt $CRIT ]; then
    echo "foo"
    aplay ~/apert.wav
    notify-send "Battery-Low"
    echo "bar"

The sixth line from above which is notify-send "Battery-Low" works just as you'd expect in terminal.
But when the script is executed it just spits out foo and bar on stdout.
I have no clue what the problem might be.

  • Are you invoking this script at a shell prompt? If not, how? Sep 24, 2015 at 22:43
  • I made the file executable. and all I'm doing is ./test.sh in the directory of the file inside M-x shell of emacs.
    – Bibek_G
    Sep 25, 2015 at 2:27
  • Well, that had me thinking. Turns out the script runs just fine from terminal emulator. I can't see why it shouldn't work from inside of emacs shell! Also the aplay line gives me some error too.
    – Bibek_G
    Sep 25, 2015 at 2:42
  • Did you ever figure this out?
    – iggy12345
    Apr 10, 2020 at 1:43

1 Answer 1


You are missing some environment variables, most likely the DISPLAY one. You could try the following:

echo "foo"                                                   
DISPLAY=:0.0 notify-send "Battery-Low"                                    
echo "bar"

If that doesn't help, you could compare the environment inside the script and in a terminal by running the env command in both.

Also note that if the script is being run as root, you may have to do something like this:

sudo -u yourUsername DISPLAY=:0.0 notify-send 'Battery low'
  • I was indeed running the script as root. But the notification still doesn't appear when I do sudo -u bibek DISPLAY=0.0 notify-send "battery-low". It doesn't give me any error either.
    – Bibek_G
    Sep 25, 2015 at 2:50
  • 1
    @coder_Bibek You also need to set the variable DBUS_SESSION_BUS_ADDRESS to what it is in your normal session. We can give more guidance if you explain how you run the script, what you've said about that so far is strange (as root and inside Emacs? are you running Emacs as root?). Sep 25, 2015 at 8:08
  • Note that there should be a : before the 0.0 for it to work. But yes, notify-send needs the session bus as well, and I can't think of a clean way to get it... Check with env to see if it's set?
    – tripflag
    Sep 25, 2015 at 8:15
  • env | grep DBUS give me same output DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus on both the shells as root and as user bibek. And yes, I am running emacs as root with sudo emacs & from the terminal emulator. (Accessing root files with normal emacs session is painful, at best; and I'ven't given other methods a try yet.)
    – Bibek_G
    Sep 25, 2015 at 10:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .