Simple pop-up notifications

simple_linux_notifications

[Kristofer] shares a tip on a simple way to add pop-up notifications to Linux scripts. The package libnotify allows you to use the command “notify-send” to pop up a message when you need it. The syntax is simple enough, just place your message in quotes after the command like so:

notify-send "Go read hackaday.com"

There are a lot of other options that go along with this command such as adding an icon and setting how long the message will be displayed. This would be great for projects that interface through scripts, displaying messages as events happen. For Ubuntu, installing this package was as simple as “sudo apt-get install libnotify-bin”.

Comments

  1. DarwinSurvivor says:

    How is this a hack? This is a simple command line utility that has been around for years doing exactly what it was meant to do.

    This is the GUI version of “print ” for linux.

  2. Dan Fekete says:

    For ubuntu, install the libnotify-bin package.

    sudo aptitude install libnotify-bin

  3. xiao_haozi says:

    Yeah agree with darwinsurvivor… this isn’t a hack but, rather, a way to use the libnotify package. There are many ways to do so including pynotify (for use in python) and other tools like zenity and so forth.

    Handy tip though… and if anyone is looking to use this for scripts, I would recommend wrapping everything in some python and just using pynotify for the notification portion.

  4. MrX says:

    It is indeed simple and obvious for long time GNU/Linux users but it is still a good tip for new
    users. Also it is hardly a hack.

    Just my 2 cents: If you want to write text on your screen like a OSD, try the osd_cat command provided by the libxosd package.

  5. octelcogopod says:

    not to be a a macfag, but growl has been around since 2004

  6. Terry says:

    macfag, how do you do this in a shell script in OSX? I’m making the switch from Ubuntu to OS X.

  7. Matthew says:

    I have been popping notifications up for a while, with xmessage. Does this package offer any sort of advantage, such as, for example, console notifications? That would be news to me.

  8. Thumbs up from me. Even if the package has been around a while, it’s always nice to have attention called to something I don’t specifically search for. I’ll be playing with it alongside pynotify for my next project.

  9. ak77 says:
  10. jojo says:

    Good to see that a windows utility I’ve had since 1996 is available on linux and mac (since 2004).

  11. xiao_haozi says:

    “Good to see that a windows utility I’ve had since 1996 is available on linux and mac (since 2004).”

    …. just because you are seeing someone post about a tip from linuxjournal now, does not mean it is a new utility.

  12. FiveseveN says:

    Hey Mike, what theme are you using :) That taskbar looks mighty smooth.

  13. Mike Szczys says:

    @fiveseven: I’m using the “New Wave” theme. I believe it comes standard with Ubuntu 9.04

  14. simonvc says:

    What _is_ a hack is this little script that lets root send messages to the current logged in users X session.

    simonvc@katana:~$ cat /usr/local/bin/root-notify-send
    #!/bin/sh

    #find out who is running X by looking for the screensaver

    UU=$(ps -ef | grep gnome-screensaver | grep -v grep |awk ‘{print $2}’)
    US=$(ps -ef | grep gnome-screensaver | grep -v grep |awk ‘{print $1}’)
    ESS=$(iwconfig eth1 | grep ESS | awk ‘{print $4}’ | sed s/ESSID:// | sed s/\”//g )

    DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$UU/environ | sed s/DBUS_SESSION_BUS_ADDRESS=//)

    sudo -u $US DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS /usr/bin/notify-send “$*”

  15. somehelp says:

    I agree, not a hack. For brevity I have clipped the most relevant definition:

    * Main Entry: hack (2)

    6 : a usually creative solution to a computer hardware or programming problem or limitation

    Now if there is an official definition that applies, by all means let me know.

  16. matschi says:

    A nice hack would be to write a dbus library for arduino. It is possible to connect dbus via tcp/ip. Authentication is still a task though..

  17. chango says:

    Hey kids, did you know you can write messages to the system log with the “logger” command?

    It’s true!

  18. Sariel says:

    I have to agree that this isn’t a hack, but it really keeps you up to date on things going on with your server. so its more of a production utility than a hack.

  19. Eraser says:

    Thats the thing guys, like D1g1talDragon said,
    “Even if the package has been around a while, it’s always nice to have attention called to something I don’t specifically search for.”
    Who cares if there is something older or newer. Thats not why I visit Hackaday ever day. So I wasn’t thinking about my particular scripts giving feedback with popups, but than I saw this article, and although I had prior knowledge of other ways of creating popups, it was the injection of the idea that helped me out. So stop your flippin whining about this not being up to your standard.
    Hackaday: Keep up the good work.

  20. MrX says:

    @jojo
    And which utility is that? You are full of shit.

    Since you first started the “we had it first” flame war, take this dumbass:

    xmessage command which does the same is available since the early beginnings of X11 servers.

    http://en.wikipedia.org/wiki/X_Window_System

    “The current protocol version, X11, appeared in September 1987.”

    Good to see that a UNIX utility I’ve had since 1987 is available on windows (since 1996).

    Suck it, LOL.

  21. rofl says:

    @jojo: pwnd! winfaggot

  22. spindizy says:

    Wow, now with e-dawg gone, this place is turning into /b/ for geeks.

  23. scenekid says:

    notify-send “hackaday.com publishes excellent posts”

  24. kkkkkkkkkkkk says:

    notify-send “hackaday.com publishes excellent posts

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 92,324 other followers