Different ways of Running Fortune command on a Graphical Interface

While I was writing about fortune a few days ago, I kept thinking how could this software be useful to a regular user. Almost everyone works on the graphical environment and although fortune is fun, but using terminal for it might not be favoured by everyone. So, I found some cool ways to get the fortune cookies on your Desktop(through web or system apps) and on your mobile phones (through RSS feeds).

Using Libnotify

Lets begin with something I did to get the fortune cookie on the gui. I made use of the libnotify library to show them in the form of notifications. I wrote a script, placed it as a launcher which fetches a cookie everytime it is executed and shows it as a notification.

Did I say script? Well, I can assure you that I still don't know a single libnotify command, I just used the example scripts mentioned in the /usr/share/doc/python-notify/examples/(on ubuntu/debian only). And yes, the script was of python, so do install python-notify before moving on.

[shredder12]$ sudo aptitude install python-notify

[root]# yum install notify-python

All you need are basic python and copy-paste skills . Here is the basic script I made out of the example ones. It may fail on many levels, but don't judge until you can write your own ;).


#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import pynotify
import sys
import os

if __name__ == '__main__':
        if not pynotify.init("Basics"):
                sys.exit(1)

        c_pipe = os.popen("fortune -c");
        cookie = c_pipe.readlines();

        summary = cookie[0][1:-2];
        string = "";

        for i in range(2,len(cookie) - 1):
            string = string + cookie[i][0:-1] + " ";

        string = string + "\n" + cookie[-1];

        uri = "file:///home/sahni/Scripts/cookie.png"

        n = pynotify.Notification(summary, string, uri);
        n.set_urgency(pynotify.URGENCY_LOW)

        if not n.show():
                print "Failed to send notification"
                sys.exit(1)

In order to get an image in the notification, do change the value of uri variable with correct address. Now, copy the code to a file, save it and change the permissions to executable

[shredder12]$ chmod a+x notify.py

Now, execute it using the following command

[shredder12]$ ./notify.py

Using the same command you can also create a launcher, click it whenever you want a notification.

Some other ways of getting the fortune cookies other than a terminal are

A simple online version of Fortune

Fortunefortoday is a small web service showing you a single fortune at time. Hit the button "get new one" to generate a new fortune. Its like an online version of fortune.

A slideshow of Fortunes

Fortunemod is also a webservice, but instead of a simple html page, its a slideshow of random fortunes. It even provides you with options to configure the slide show.

A RSS feed of Random fortunes

This is a really useful service. It provides you with the options of a configurable RSS feed of fortunes. One can even set the limit on long fortunes and use the service on mobile phone feed readers.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.