"dynamic" menus in fluxbox

howto create dynamic menus in fluxbox. its a an older article i once wrote for the original fluxmod.dk-site (mirror). it had also kind of influence to the creation of fbnews

after a little discussion in the #fluxbox-channel i decided to write a little article about dynamic menu-entries. other windowmanagers support perl or python in their menus, fluxbox doesnt. this article explains how to get things done even if no scripts can be executed from within the menu.

there is no script-support in the menu (or at any other place) in fluxbox (yet?). but what if one wants to have some dynamic content or whatever you like? well, thats easy. all we have to do is to get the content, save it into a file and do some magic in our fluxbox-menu. lets start from the end:

the “magic” is called the [include] command. it works as the following:

[submenu] (news)
  [include] (~/.fluxbox/news)

this will create a submenu in our menu called “news” and in that submenu there are, lets say, hourly updated headlines. at least thats the plan.

so, first we need is the included file. lets assume we have a nifty
newsfetcher. i ll call it rnews since its .. uhm .. my newfetcher :) it grabs a rdf-page and puts the content to the stdout.

$> rnews -- -m sl

which will result in:

10.[A History of Portable Computing]
9.[Mozilla Foundation Chief Mitchell Baker Replies]
8.[Web Design Hampers Mobile Internet?]
7.[Ubuntu and UserLinux to Combine?]
6.[Adobe Acrobat Toolbar Worse than Malware?]
5.[Beginning PHP 5 and MySQL E-Commerce]
4.[Brainshare Reports: NLD 10, Novell's Linux Switch]
3.[Plants May Be Able To Correct Mutated Genes]
2.[Review of the 8 Hour Tablet: Electrovaya Scribbler]
1.[The Solar Death Ray]

well, thats a good start. this content we need to convert into the
fluxbox-menu-syntax. first we need to bring titles and the urls on
one line:

$> rnews -- -m sl | sed '/^$/d' | awk '{ printf $0" " ; getline ; print }'
10. [A History of Portable Computing] http://<restofurl>
9. [Mozilla Foundation Chief Mitchell Baker Replies]      http://<restofurl>
8. [Web Design Hampers Mobile Internet?]      http://<restofurl>
7. [Ubuntu and UserLinux to Combine?]   http://<restofurl>
6. [Adobe Acrobat Toolbar Worse than Malware?]   http://<restofurl>
5. [Beginning PHP 5 and MySQL E-Commerce]   http://<restofurl>
4. [Brainshare Reports: NLD 10, Novell's Linux Switch]   http://<restofurl>
3. [Plants May Be Able To Correct Mutated Genes]   http://<restofurl>
2. [Review of the 8 Hour Tablet: Electrovaya Scribbler]   http://<restofurl>
1. [The Solar Death Ray]   http://<restofurl>

beautiful, isnt it? next step is as easy as the rest before. we need each line been transformed as:

[exec] ( title ) { command url }

which can really easily be done with

$> rnews -- -m sl | sed '/^$/d' | \
     awk '{ printf $0" " ; getline ; print }' | \
     sed -e 's/^(.*)[[:space:]]+(http.*)/[exec](1) {konqueror 2}/g'

ah, damn sexy. pipe this to ~/.fluxbox/news and .. well .. thats it.
now you have a submenu called “news” in your fluxbox menu with all the headlines from slashdot. yeah, perfect. and even better, if you click on the titles in the submenu, a new konqueror will open up and surf to the related url.

well .. there is a last problem. the headline are getting really fast
really old. there must be a way to update the news-file.

think think

and a voice from nowhere whsipers the magic words: cron

yeah, we put the complete commandline in a script and use the crondaemon of the system to run the script every x minutes, hours, whatever. or,use batch or at.

advantages of this method to create the menus:

  1. it keeps fluxbox small and clean if no script-code is added, no further deps, less potential bugs.
  2. the display of the menu will always be as fast as hell. if the script takes some time, who cares? its not the menurendering that is slowed down
  3. you can use any input u want:

scripts, mails, sms, whatever you want. the only thing thats necassary is the format for the file


  1. its not obvious
  2. the transform process requires some script-skills.

but .. hey .. the topic was: how to get the output of a script into fluxbox-menus” so at least a tiny bit of script-skillz are necessary :)

you can find the original “backup” of the article here.