Howto: Desktop “widgets” for the console

It’s time to talk about a “desktop widget” for the console, and you’ll have to use your imagination a little bit on this one. After all, consoles don’t really have “desktops,” and the idea of a “widget” on the desktop that refreshes periodically and displays cutesy text, a la conky or gdesklets/adesklets, is a little counterintuitive. And console geeks dislike anything fluttery or flashy anyway, and the mere suggestion might be somehow irritating. :)

But be honest — what’s the difference between the left and the right? (I hope Onyros doesn’t mind if I borrow an old screenshot. …)

 

Both sides have a system profiles, a clock, uptime meters, and so forth. Arrangement and “pretty” factor is slightly different, but the idea is the same.

So how about something a little more challenging? How about a disk usage meter? or a weather “widget”? Well, how does this grab you?

That’s a lot to take in at once, so here’s a brief explanation. In the upper left hand corner are the weather conditions for Osaka, Japan, and next to that is cdf, which is showing a quick disk usage display. The weather report is running inside elinks, and refreshes every 10 minutes (even though the weather report itself isn’t updated for a matter of hours. This is an example, see? ;) ). cdf spits out a new analysis every 10 seconds, although that too is overkill for the machine. My drive space doesn’t change that quickly.

The entire business is split up by screen-vs — which is only the best thing since sliced bread — and so I also have mc on the left, hnb at the upper middle, and tty-clock at the lower middle. At the bottom are the load readouts from htop, which is in there only because it could be thought of as another example of a “widget.”

So how do they update? Well, htop and tty-clock update themselves, so there’s no trick involved in that (I daresay neither would be very useful if they didn’t update, really :roll: ).

cdf, on the other hand, is a one-shot application, and doesn’t recur unless I tell it to — like this:

while true ; do cdf -t ext2 -hm ; sleep 10s ; clear ; done

So long as that terminal window continues to run, that will loop through, refreshing every 10 seconds. I can stop it at any time by pressing CTRL+C, and recue it or adjust the flags or what have you.

Most little one-line applications like that will work fine that way; you could have a brief upload/download meter display like that, or list the users on your machine, or even just spew out a date. Trap it in a tiny box in your screen setup, and it will continue on gleefully, for as long as you let it.

What about that weather report? Well, that’s a little trickier. Taking a cue from Jerris Welt, who wrote a nifty post called “Scripting screen for fun and profit,” the same sort of thing is possible with elinks and screen, with some tiny adjustments.

elinks by default, I believe, uses only the CTRL+R key to refresh a page. We can feed elinks a refresh command while it’s pointed at the weather reports available here, and using the same while true-style loop, refresh that page every few minutes. (You will have to hunt down your own METAR code and find it in that directory. This time, Google is your friend.)

The problem I encountered was that escape codes and control key codes didn’t feed through screen’s stuff option like I thought they would. As always, it was probably my fault and easy enough to fix, but it was just as easy to set elink’s options to accept another keystroke as a “page refresh” command, and send that through. In my case, I used the at-symbol, which means the loop looks like …

while true ; do screen -p weather -X stuff @ ; sleep 600s ; done &

The weather “widget” has to be in a screen “window” labeled “weather”, and note the ampersand at the end of that line. That forks the command off into its own little world, meaning I can close the bash prompt and it will continue to refresh. I didn’t do that with the first example because I wanted that prompt to remain attached to the cdf output. Here, it’s not necessary, so I can close that and let it spin in the background. Next step is of course, to trap that in a little box in your screen-vs arrangement and — voila! you have your own little desktop weather bug that updates regularly.

There are other ways to do this, of course. You could look at the venerable but nonetheless excellent weather-util script, which reads the same information from the same site, and reformats it in a different style. Set that to cycle in the same way as cdf, and you get the same effect.

But a lot of people I know have a preference for a web-based weather page, and this would allow you to load and refresh it regularly, in widget fashion. Keeping in mind that elinks adds a menu bar and a status bar and a tab bar, you might also prefer to look at a different text browser — something like w3m might not eat up so much space.

And of course, if you’re not using an 8-year-old laptop with an 800×600 LCD, you might have an easier time arranging things as you like. ;)

P.S.: This is one of those times when using screen-vs in conjunction with dvtm might be useful; dvtm might be easier to arrange, might organize all your “widgets” together, and might allow you to “pop” them out of the screen display as a group, when they get in the way. You be the judge. :mrgreen:

About these ads

9 Responses to “Howto: Desktop “widgets” for the console”


  1. 1 Colin 2009/12/18 at 3:53 AM

    You may also look into “watch” instead of making a periodic loop to run your programs. For example…

    while true ; do cdf -t ext2 -hm ; sleep 10s ; clear ; done

    would be

    watch -n 10 -t cdf -t ext2 -hm

    Watch clears itself between each interval, so no need for the ‘clear’. Something I’ve used myself in the past, and something I find a little cleaner.

  2. 3 ing 2009/12/18 at 8:49 AM

    You know, conky can output to the console with “out_to_console yes”.

    • 4 K.Mandla 2009/12/18 at 9:06 AM

      I was not aware of that, thanks. I’ll have to try it out and see what trouble I can get into. … ;)

      • 5 Bryan 2009/12/18 at 12:41 PM

        There’s a pkgbuild for a special conky build that doesn’t require any X libs called conky-cli in the AUR, you could very easily change it to a PKGFILE for crux.

  3. 6 Onyros 2009/12/20 at 4:08 AM

    I don’t mind at all, obviously ;)

    I still have those ISO’s lying around, never found them good enough to get them out there, though.

    You made me want to reinstall Fluxbox and that particular configuration, but ever since going Awesome –> DWM I’ve found MY environment. That one’s still looking pretty good, though and I do remember the memory usage being very, very low, almost Slitaz low.

    Cool to see what has evolved in terms of programs I used (and endorsed) back then – 2 years and a half ago, already! – and what I’m using now!

    I’m no longer using Conky, though. I have a self-made script piped to DWM’s “status bar”, and a terminal window with iftop as a network monitor.


  1. 1 Mild enthusiasm for conky-cli « Motho ke motho ka botho Trackback on 2009/12/18 at 9:12 PM
  2. 2 Links 18/12/2009: More GNU/Linux Migrations, GNOME 3.0 Preparations | Boycott Novell Trackback on 2009/12/18 at 11:40 PM
  3. 3 GoblinX Project » GoblinX Newsletter, Issue 231 (12/20/2009) Trackback on 2009/12/20 at 9:30 PM

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




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,957,906 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: