Results 1 to 7 of 7

Thread: pynotify every ten minutes

  1. #1
    Join Date
    Mar 2009
    Beans
    41

    pynotify every ten minutes

    Short version: How do I automate a libnotify notification occurring every ten minutes? Or what might be better for this than libnotify/pynotify?

    I am trying to build a random notification program. The idea will be to randomly show information from a text file every ten minutes; quotes, to-do items, perhaps Twitter updates dumped into a file. Right now I have the following code, which displays a fortune.

    Code:
    #!/usr/bin/env python
    
    import os
    import pynotify
    
    pynotify.init("random information")
    s = os.popen("fortune -n 100 -s","r").read()
    n = pynotify.Notification("Fortune",s)
    n.show()
    However, when I tried to run this every ten minutes with cron, it didn't show, even though I was able to successfully run it as root. (I tried the root crontab and my user crontab...) So I'm thinking it doesn't get access to my X instance, or perhaps the running notifier daemon, or whatever libnotify needs, when it's run by cron.

    Anyone know how I could get this simple script to run every ten minutes?

    Additionally: Ultimately, when this actually notifies me of useful things rather than just silly quotes, I'll want to be able to attach notifications to arbitrary bash commands or executables. I would want to click on them to launch some behaviour. What could I use to accomplish that? I've found something called mumbles but don't know if it has that feature yet; notify-osd (called by pynotify unless interactions are added to the notification) doesn't. Is there another, featureful notification option?

  2. #2
    Join Date
    Feb 2007
    Location
    New York
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: pynotify every ten minutes

    Scratch what I wrote. I didn't realize your script actually works.

    libnotify uses dbus, and I hear cron has trouble talking to dbus. You have to get the right dbus instance first or something.

    http://ubuntuforums.org/showthread.php?t=615882

    Also, could you just use time.sleep(10*60) and put a loop in your script?

    What do you mean by "attach notifications to commands"?
    Last edited by Endolith; July 22nd, 2009 at 01:49 AM.
    "Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct

  3. #3
    Join Date
    Jun 2007
    Location
    Oklahoma City, OK
    Beans
    200
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: pynotify every ten minutes

    Why not have python run the loop every 10 minutes?
    Te audire no possum. Musa sapientum fixa est in aure.

  4. #4
    Join Date
    Jan 2007
    Location
    Michigan, USA
    Beans
    1,184
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: pynotify every ten minutes

    Maybe you want to daemonize this script, and make it run persistently. You can have interrupts, and catch system signals. Ultimately it may be more flexible.


    There are lots of tutorials available.

    I wrote a similar notification daemon for asterisk in perl, and it wasn't very hard at all.

  5. #5
    Join Date
    Feb 2007
    Location
    New York
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: pynotify every ten minutes

    This might be a solution:

    http://www.chicagolug.org/pipermail/...ly/000734.html

    "Gnome Schedule does not support yet setting environment variables for recurrent tasks, but it will do soon. In the meantime, you can manually create a script that first defines DISPLAY variable and then calls the graphical application. Finally, you can create a recurrent task to launch the script."
    Last edited by Endolith; July 22nd, 2009 at 03:31 AM.
    "Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct

  6. #6
    Join Date
    Feb 2007
    Location
    New York
    Beans
    894
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: pynotify every ten minutes

    This worked for me:

    http://wwwjfy.blogspot.com/2009/03/p...h-crontab.html

    Code:
    40 22 * * 1-5 env DISPLAY=:0.0 /home/endolith/Applications/bedtime.py #JOB_ID_2
    Whyyyyy must Linux be so difficult?
    "Please remember to do things the Ubuntu way. There is always more than one solution to a problem, choose the one you think will be the easiest for the user. ... Try to think as a green user and choose the simplest solution." — Code of Conduct

  7. #7
    Join Date
    Jun 2007
    Location
    Oklahoma City, OK
    Beans
    200
    Distro
    Kubuntu 10.04 Lucid Lynx

    Re: pynotify every ten minutes

    Quote Originally Posted by Endolith View Post
    This worked for me:

    http://wwwjfy.blogspot.com/2009/03/p...h-crontab.html

    Code:
    40 22 * * 1-5 env DISPLAY=:0.0 /home/endolith/Applications/bedtime.py #JOB_ID_2
    Whyyyyy must Linux be so difficult?
    Well, that's really more because of X and not Linux. Since there can be multiple X servers running on a machine, it can't automatically assume which one you intended. Think of it like running a Scheduled Task on a Windows Terminal Server.
    Te audire no possum. Musa sapientum fixa est in aure.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •