Geektool Geeklets

Build an Attractive, Informative Mac Desktop with GeekTool aurel / 27 avril 2014 It may be covered with applications and windows most of the time, but your Mac’s desktop can also be an excellent source of information, including the time and date, available hard drive space, battery status, system performance, and more. I love GeekTool, but ran into a roadblock when one of my geeklets caused it to freeze on startup, and I couldn't remove the offending widget from within the System Preferences panel.So, after digging around, I discovered that the geeklets are stored as plist files at /Library » Preferences » org.tynsoe.geeklet. You can open these files in the Property List Editor (or PListEdit Pro),. When you’re done and exit GeekTool, all of the borders around your geeklets, which can admittedly make everything seem like a mess, will disappear. If you find that GeekTool is causing your computer to run slow, check the refresh rate of your geeklets. Too many geeklets refreshing too often may cause problems.

Geektool Geeklets. By terbowalltrac1970 Follow Public. Heres the original site: Dont see a place to add shadows.Color, font, etc, but no shadow.

Geektool Geeklets

42 Astoundingly Useful Scripts and Automations for the Macintosh

2019 August 23/6:00 AM

Work faster and more reliably. Add actions to the services menu and the menu bar, create drag-and-drop apps to make your Macintosh play music, roll dice, and talk. Create ASCII art from photos. There’s a script for that in 42 Astounding Scripts for the Macintosh.

  • Amazon

GeekTool’s “shell” Geeklet is a great way of displaying the results of command-line scripts on your desktop. I currently have the following shell Geeklets on my computer for monitoring my sites:

  • /usr/bin/curl http://www.example.com/server-status?auto
  • /usr/bin/ssh monitor@web /usr/bin/uptime
  • /usr/bin/ssh monitor@web '/bin/ps -axe | /usr/bin/grep httpd | /usr/bin/wc -l | /usr/bin/sed -E 's/ +//;'
  • /usr/bin/ssh monitor@web '/usr/bin/tail -40 /var/log/apache2/error_log'
  • /usr/bin/ssh monitor@web bin/freemem
  • /usr/bin/ssh monitor@web bin/hightimes

The first one is just grabbing the text version of Apache’s server status page. The second one displays the uptime and current load. The third one counts up the number of httpd processes currently running. And the fourth one displays the last 40 lines of Apache’s error log.

Looking at system stats is as simple as using Expose to pull all windows aside and reveal the desktop. “The memory’s green, the system is clean.”

The final two are a little more complex: freemem and hightimes are Perl scripts I’ve written to display color-coded warnings. It’s easy to add ANSI escape codes using Perl. The escape character is ‘e’. Follow it by an open bracket, the code, and the letter m1. Look for the codes on Wikipedia’s ANSI escape code.

[toggle code]

  • #!/usr/bin/perl
  • $critical='e[31m'; #red
  • $warning='e[35m'; #magenta
  • $notice='e[33m'; #yellow
  • $clear='e[0m';
  • @processes = `/bin/ps -u _www -o time,pid | /usr/bin/sort -nr`;
  • for $process (@processes) {
    • chomp $process;
    • if ($process =~ m/^ +([0-9:.]+) +([0-9]+)/) {
      • ($time, $processId) = ($1, $2);
      • if ($time =~ m/([0-9]+):([0-9]+).([0-9]+)/) {
        • ($hours, $minutes, $minuteFraction) = ($1, $2, $3);
        • if ($hours) {
          • print '$critical$process$clearn';
        • } elsif ($minutes > 10) {
          • print '$warning$process$clearn';
        • } elsif ($minutes > 5) {
          • print '$notice$process$clearn';
        • } else {
          • #at the end of cputime-intensive processes
          • exit;
        • }
      • } else {
        • print '${critical}UNKNOWN TIME FORMAT: $time$clearn';
      • }
    • }
  • }
Cached

This runs the ‘ps’ command, getting only processes owned by _www, and displaying only the time and pid columns. The results of ps get piped through sort so that the most time-consuming processes are at the top.

Processes owned by _www that take up a lot of cpu time are displayed in red; those that might be about to take up a lot of cpu time are displayed magenta; and those that are probably just dipping over the line temporarily are displayed in yellow. Otherwise, it doesn’t display at all.

[toggle code]

  • #!/usr/bin/perl
  • $okay='e[32m'; #green
  • $critical='e[31m'; #red
  • $problem='e[33m'; #yellow
  • $clear='e[0m';
  • $usage = `/usr/bin/vm_stat`;
  • $warning = $critical;
  • if ($usage =~ m/page size of ([0-9]+) bytes/) {
    • $pageSize = $1;
    • if ($usage =~ m/Pages free: *([0-9]+)/) {
      • $free = $1;
      • $free = int($free*$pageSize/(1024*1024));
      • if ($free > 8000) {
        • $warning = $okay;
      • } elsif ($free > 6000) {
        • $warning = $problem;
      • }
      • $message = '$free megabytes free';
    • } else {
      • $message = 'Unable to find free pages';
    • }
  • } else {
    • $message = 'Unable to find page size';
  • }
  • print $warning, $message, $clear, 'n';
  • if ($warning eq $critical) {
    • exit(1);
  • }

This parses the output of vm_stat to get the current free memory. It also will adjust the green response dot you see in some of the screenshot’s geeklets. The green dot normally means only that the script did okay. For direct commands, you can’t make it be anything else. For your own scripts, however, if you want to change the color of that button you can exit with an error. In Perl, this is as simple as “exit(1)”.

Scripts

That’s why the free memory script checks to see if the warning is critical before exiting. If the free memory is low enough to justify a critical color code, the script exits with an error code. GeekTool responds to this by turning the normally green dot red.

The hightimes script doesn’t bother with an exit code because it doesn’t display anything at all if there’s nothing out of the ordinary.

Obviously, this isn’t a replacement for a good system monitoring tool like Zenoss2. But for keeping an eye on something command-line oriented through both good and bad, GeekTool is a great little tool.

Note: I’m guessing what the time format is for ps in the first script. I don’t understand what the “ps.1p” means in %l:ps.1p, in the man page description. That’s why I have an error condition for unknown time formats.

February 10, 2011: Using Term::ANSIColor with GeekTool

I was looking for something else this morning and ran across Term::ANSIColor. Instead of having to look up the color codes in a table and output them exactly right, Term::ANSIColor makes manipulating ANSI codes much easier—and thus less likely to error.

There may be some cases where I don’t want to introduce any dependencies or overhead, but for the most part, Term::ANSIColor should be a much better choice.

In each of the two scripts, it’s just a matter of replacing the variables. Instead of:

Geeklets
  • $critical='e[31m'; #red
  • $warning='e[35m'; #magenta
  • $notice='e[33m'; #yellow
  • $clear='e[0m';

Import Term::ANSIColor:

  • use Term::ANSIColor;
  • $critical = color 'red on_black';
  • $warning = color 'magenta on_black';
  • $notice = color 'yellow on_black';
  • $clear = color 'reset';

Everything else remains the same.

And for the vm_stat script:

  • use Term::ANSIColor;
  • $okay = color 'green';
  • $critical = color 'red';
  • $problem = color 'yellow';
  • $clear = color 'reset';

One odd issue I ran into is that GeekTool appears to need the ‘reset’ to be followed by a carriage return. Running this Whammy Burger script directly on the command line will act normally—print the text in green—but running it in GeekTool will display an “[0m” at the end of the green text.

  • #!/usr/bin/perl
  • use Term::ANSIColor;
  • print color 'green';
  • print 'Whammy Burger!n';
  • print color 'reset';

GeekTool - Customize Your Mac Desktop!

The solution is to move the final ‘n’ below the reset.

  1. I’m not sure what the ‘m’ means. Monitor?

  2. Which is what provides the graphs in the screenshot. They’re created using Zenoss and displayed via a public URL, using Geektool’s image geeklet.

ANSI escape code
“ANSI escape sequences are used to control text formatting, color, and other output options on text terminals.”
GeekTool
“GeekTool is a System Preferences module for Mac OS 10.5. It lets you display on your desktop different kind of informations, provided by 3 default plugins.” The plugins let you monitor files (such as error logs), view images (such as live graphs), and display the results of command-line scripts.
Zenoss
“Open Source Server and Network Monitoring”. Zenoss is built in Python and, at least on OS X, was very easy to set up.

Geektool Scripts Geeklets

More GeekTool

Tool Geek

icalBuddy and eventsFrom/to
Ali Rantakari’s icalBuddy has an error in the documentation for the “eventsFrom/to” command-line option. Rather than “tomorrow at time” use “time tomorrow”.
Put a relative clock on your Desktop with GeekTool
There are a lot of desktop clocks that show the absolute time. But sometimes you just want to know if the time is today, or yesterday, or two days ago. Here’s how to do it with Python and GeekTool.
Apple Mail on the Desktop with GeekTool
Here’s a simple AppleScript to use with GeekTool to put your inbox on the Desktop.
GeekTool, TaskPaper, and XML
A script to convert a TaskPaper file to XML so as to filter it for specific tags and display the results on the Desktop.
Command-line mail on OS X: re-alpine and Geektool
If you do a lot of automated command-line scripts, you probably also generate a lot of mail to /var/mail. OS X only has the mail program built-in, and its GUI mail client hasn’t been able to add simple mail accounts since about OS X 10.2. Alpine can get you a better mail client, and Geektool can provide better notices.