Tutorial – Desktop News Feeds

Pipe Menus

The menugenerator script should work with any window manager that follows freedesktop.org standards. Before showing a fallback solution for cases when those standards are not applicable, I want to show you a cool alternative solution that is only valid for the Blackbox family of window managers (e.g., Openbox and Fluxbox): pipe menus.

Pipe menus are window manager applications that apply the old Unix practice of doing complex stuff by connecting (piping) small tools together, each of which does one thing well. A pipe menu is created on the fly not by reading .desktop files but from plain text output of any program you desire. Pipe menus can display and do practically anything, from checking email to reading your horoscope.

My very simple RSS menu generator for Openbox is called rssmenu (Listing 8). This code reads the same file as the previous script and parses it in the same way. The only difference is that it formats the output not as a .desktop file, but with the markup required by Openbox [9].

Listing 8

rssmenu

 

Figure 5 shows how to bind the rssmenu script to an Openbox submenu entry with the Obmenu tool. Figure 6 displays what happens, in practice, when you select the corresponding mynews submenu inside Openbox: again, clickable news headlines in a very quick and discrete interface.

Figure 5: The Openbox window manager has a nonstandard but powerful way to build menus on the fly with scripts, and the Obmenu tool makes it easy to activate them.
Figure 6: The same dynamic mynews menu seen in Enlightenment, here built in Openbox with Pipemenu activated in Figure 5.

Zenity

As cool as they are, the ways to embed headlines dynamically in Linux system menus shown so far are not applicable to window managers that, for whatever reason, do not offer such menus. These days, this is mostly the case of tiling window managers like i3, which are deliberately designed to never show root windows.

In all these cases, you can still achieve an equivalent functionality with the Zenity utility [10]. Figure 7 shows the Zenity dialog you get when you launch the script in Listing 9 from a prompt or a hotkey of your choice.

Figure 7: Zenity is a viable alternative for window managers that do not support root window menus. Select any combination of news you want, click OK, and it will open in new Firefox tabs.

Listing 9

zenitymenu

 

The general scheme is always the same: read headline titles and URLs from the rssmix file and open in Firefox tabs (lines 18-22) all those selected by the user in the Zenity dialog. The Zenity options in line 16 are self-explanatory; what matters is how it exchanges data with the rest of the script:

  • The cut command extracts headline titles from rssmix and passes them to the zenity standard input.
  • The zenity output is saved in the $HEADLINES variable, which has the format:
Red Hat Reports $823 Revenue|Navarro: Kavanaugh should step aside|Debian, Ubuntu... Leaving Users Vulnerable

The loop starting in line 22 reads those titles from $HEADLINES using the pipe ('|') character as the field separator to open the corresponding URL in Firefox (line 21). The script knows which URLs correspond to each title because they constitute key-value pairs in the NEWSURLS associative array defined in line 4, filled in line 13, and looked up in line 21. Yes, it would have been possible to use Zenity in a way that would not need an associative array. Fact is, I really wanted to show you how to use those powerful data structures in a shell script.

Conclusions

You can use the menu generation methods for much more than creating headlines as clickable menu entries: Please let me know what you make of them.

As far as RSS goes, it is wonderful, but the best way to use it productively remains careful planning and self-discipline. Here, I show you a starting point, but we each have different needs. The following are just a few examples of the many ways you can play with the scripts you saw here:

  • Create many separate menus, each with its own topic (e.g., work, hobbies, general news), number of headlines, and refresh frequencies to minimize distractions. For example, you could load work feeds daily and entertainment feeds only on weekends or in the evenings).
  • Pass headlines to speech synthesizers that read them to you.
  • Save headlines automatically as bookmarks.
  • Use the scripts to build a self-refreshing web page in HTML, and make that the home page of all your browsers.
  • Mix and display headlines from different sources in dedicated website sidebars, as I do on my main blog [11].

The Author

Marco Fioretti (http://mfioretti.com) is a freelance author, trainer, and researcher based in Rome, Italy. He has been working with free/open source software since 1995 and on open digital standards since 2005. Marco also is a board member of the Free Knowledge Institute (http://freeknowledge.eu).

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Good News

    Create the perfect mix of news with an RSS aggregator. Linux supports several open source aggregators, or, if you're looking for the perfect fit, you can even create your own.

  • Perl: Collecting News Headlines

    Instead of visiting news sites periodically to pick up the latest reports, most people prefer to let a news aggregator do the job.The aggregator automatically draws your attention to incoming news. If a website does not have an RSS feed,a new Perl module simplifies the task of programming an RSS feed for private use.

  • LibreOffice Macros with ScriptForge

    ScriptForge helps you automate LibreOffice by building portable macros.

  • Workspace: RSS Aggregators

    Read and manage your favorite feeds with open source RSS aggregators.

  • Adafruit IO API

    The Adafruit IO API offers a convenient means for network-ready sensors and other components.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News