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 ).
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.