Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm running Lubuntu 12.04. I have a shell script that tests for a network condition and need some way for it to pop up a notification in the GUI. The network testing part is done, but I need some help with the "pop up a notification in the GUI" part.

share|improve this question
    
If you want customization like alignment of them , then you can use this askubuntu.com/questions/128474/… –  AgentCool Dec 5 '12 at 2:50
    
few other links askubuntu.com/questions/189469/… –  AgentCool Dec 5 '12 at 2:51
1  

2 Answers 2

You can use the default notification daemon to give notifications with an icon.

Just add this line to the shell script where you want to give notification (with appropriate lines and paths).

notify-send -u critical -i <Icon-path> "<Heading>" "<Rest of the message>"

The package providing this is libnotify-bin.

@ThatJackElliott Did you replace <> with appropriate text? You need to remove "<" ">". Icon path is optional. Try this :

notify-send -u normal "Hello Jack Elliot" "This is a trial notification.\nWelcome to AskUbuntu\!"

-u can be low, normal & critical.

See man notify-send for more info.

In case of any problems, these are the packages in my system. They work excellently :

  • gir1.2-notify-0.7
  • libknotifyconfig4
  • libnotify-bin
  • libnotify-dev
  • libnotify0.4-cil
  • libnotify4
  • notify-osd
  • notify-osd-icons
  • python-notify
  • python-pyinotify
  • xfce4-notifyd
  • xfce4-notifyd
share|improve this answer
    
Hi, this one doesn't return anything. Just takes me back to the shell prompt. –  That Jack Elliott Dec 8 '12 at 15:10
    
Okay, still no happiness: –  That Jack Elliott Dec 9 '12 at 2:03
    
Run dpkg -l | grep notify-send and see if you get any output. –  VedVals Dec 9 '12 at 14:43
    
Nope, no output. –  That Jack Elliott Dec 10 '12 at 21:33
    
@ThatJackElliott Sorry, I gave the wrong name. Try dpkg-query -l libnotify-bin OR dpkg -l | grep libnotify-bin. If no output, install libnotify-bin. Its available in the repos. –  VedVals Dec 11 '12 at 4:08

yeah you can do that with python. open your terminal and type

sudo apt-get install python-notify

Then write a program like this .

frank@august:~$ cat>not.py
#!/usr/bin/python
import sys
import pynotify

if __name__ == "__main__":
    if not pynotify.init("icon-summary-body"):
        sys.exit(1)

    n = pynotify.Notification(
        "Hi Elliott",
        "welcome to askUbuntu!",
        ##dont remove the below line
    "notification-message-im")
    n.show()
frank@august:~$ 

save it with any name , for example noti.py for our case .

open your terminal and type python not.py

Then you will see

enter image description here

Hope that helps.

Credit goes here : Create custom notification on your Ubuntu desktop using python

share|improve this answer
    
Hi, thanks for the suggestion, but I can't get this to work. When I run the script I get:jack@jack-Aspire-one:~/bin$ sh notify.py notify.py: 2: notify.py: import: not found notify.py: 3: notify.py: import: not found notify.py: 6: notify.py: Syntax error: "(" unexpected (expecting "then") jack@jack-Aspire-one:~/bin$ –  That Jack Elliott Dec 8 '12 at 15:09
    
Wait, sorry, I didn't run the script correctly. I also can't figure out how to enter line breaks in this comment box, nor put the terminal results in a neat little box, so my responses are a bit of a mess. The python script is still returning an error: jack@jack-Aspire-one:~/bin$ python notify.py Traceback (most recent call last): File "notify.py", line 14, in <module> n.show() glib.GError: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files jack@jack-Aspire-one:~/bin$ –  That Jack Elliott Dec 8 '12 at 15:13
    
have you installed python-notify ? –  AgentCool Dec 9 '12 at 1:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.