Return to site

Geektool Geeklets

broken image


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.

5 Examples of Mac Os Desktop Customization using GeekTool. Among the Mac Os X desktop customization tools available, GeekTool is my favorite one. It is a really neat utility that will allow you to run little scripts or 'geeklets' to display useful informatiom such as RAM, CPU usage, calender, images and etc. On your Mac's desktop. Geektool itself does not appear to be hogging CPU or memory but something related to it is. It's not the geeklets as they are only echoing out some text and running df -h every 5 seconds. One thing I've noticed is that the WindowServer process seems to start eating a lot of cpu while Geektool is running. My hunch is that this is the problem - I.

  • 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]

Geektool Geeklets

  • #!/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';
      • }
    • }
  • }

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.

Webroot Spy Sweeper v5.3 (32-bit). Warhammer warriors of chaos 8th pdf reader edition.

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

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.

Rainmeter For Mac

Margonem auto exp bot. 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.

Geektool Geeklets

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:

  • $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';

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.
Tool geek

More GeekTool

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.

I've been a big fan of GeekTool for a while. It's been one of the subtle things that I've felt that separates OS X from Windows. For a while I had several widgets (called Geeklets) run by GeekTool to display various information on my desktop. A post last week by Patrick Welker (@_patrickwelker) opened me up to a new way to put widgets on my desktop.

Übersicht, from Felix Hageloh, is a great update to the GeekTool concept. Like GeekTool, Übersicht will alllow a user to create self contained widgets and have them rendered on your desktop. But what makes Übersicht stand apart from GeekTool is getting the widgets to be based on HTML 5 using either Javascript or Coffeescript as the widget file. Shifting over to using HTML 5 in Übersicht generates a much more visually appealing presentation than previously possible with GeekTool.

Widget Layout

Geektool

The basic compoents of a widget includes:

  • command [required]: The shell command that will be used to help capture what information you want to see on your desktop.
  • refreshFrequency [required]: How often you want to run the shell command to refresh the information. The integer is listed in milliseconds.
  • style [required]: The CSS styling to render the information you want shown on your desktop.
  • render [required]: The function that is used to parse the information from the command to the style to display on your desktop.
  • update [optional]: When the widget is first run, it will take the command output and display the contents via the render section. The update section replace the contents displayed based on the refreshFrequency.

An example of a simple widget to show your public IP address using a simply Python script: Gist link

Felix Hageloh, lead on the Übersicht software project, has more details on widget development on GitHub.

Geektool Geeklets

Widget differences

There are some subtle differences how GeekTool and Übersicht parse commands. GeekTool can take a shell command that you'd run in Terminal and use it for a Shell Geeklet. One common GeekTool GeekLet is displaying the availabile hard drive space on your Mac, using the following shell command:

Übersicht can parse the same command, but like most other scripting languages, it needs to know where to start and when to stop when parsing information. The section of a widget, labeled command, needs to be encapsulated in a set of double quotes - '. To do this with the disk space shell command it will need to be properly escaped like this:

If you get an error with your widget, and it includes actual text from your command, take a look at how well your command has been escaped.

Once you have the shell command working, you can start on laying out your widget.

Javascript vs Coffeescript

Widgets for Übersicht can be written in either Javascript or Coffeescript. Continuing on the example monitoring your hard drive space, I wrote two widgets as an example in Javascript and Coffeescript. Both widgets were written to display the same information from the following shell command:

Coffeescript verson: Gist link

Pure Javascript version: Gist link

Here's a comparison of the output of the two scripts:

Widget Gallery

The makers of Übersicht also have a gallery of widgets other users have created and were willing to share.

Some other widgetsI'm looking at:

  • Sysmon Set: a whole set of widgets to monitor your system.
  • Pretty Weather: a stripped down version of the weather widget I'm currently using. Looking at replacing the predicted high temperature with the current temperature. [1]
Geektool Geeklets

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:

  • $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';

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.

More GeekTool

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.

I've been a big fan of GeekTool for a while. It's been one of the subtle things that I've felt that separates OS X from Windows. For a while I had several widgets (called Geeklets) run by GeekTool to display various information on my desktop. A post last week by Patrick Welker (@_patrickwelker) opened me up to a new way to put widgets on my desktop.

Übersicht, from Felix Hageloh, is a great update to the GeekTool concept. Like GeekTool, Übersicht will alllow a user to create self contained widgets and have them rendered on your desktop. But what makes Übersicht stand apart from GeekTool is getting the widgets to be based on HTML 5 using either Javascript or Coffeescript as the widget file. Shifting over to using HTML 5 in Übersicht generates a much more visually appealing presentation than previously possible with GeekTool.

Widget Layout

The basic compoents of a widget includes:

  • command [required]: The shell command that will be used to help capture what information you want to see on your desktop.
  • refreshFrequency [required]: How often you want to run the shell command to refresh the information. The integer is listed in milliseconds.
  • style [required]: The CSS styling to render the information you want shown on your desktop.
  • render [required]: The function that is used to parse the information from the command to the style to display on your desktop.
  • update [optional]: When the widget is first run, it will take the command output and display the contents via the render section. The update section replace the contents displayed based on the refreshFrequency.

An example of a simple widget to show your public IP address using a simply Python script: Gist link

Felix Hageloh, lead on the Übersicht software project, has more details on widget development on GitHub.

Widget differences

There are some subtle differences how GeekTool and Übersicht parse commands. GeekTool can take a shell command that you'd run in Terminal and use it for a Shell Geeklet. One common GeekTool GeekLet is displaying the availabile hard drive space on your Mac, using the following shell command:

Übersicht can parse the same command, but like most other scripting languages, it needs to know where to start and when to stop when parsing information. The section of a widget, labeled command, needs to be encapsulated in a set of double quotes - '. To do this with the disk space shell command it will need to be properly escaped like this:

If you get an error with your widget, and it includes actual text from your command, take a look at how well your command has been escaped.

Once you have the shell command working, you can start on laying out your widget.

Javascript vs Coffeescript

Widgets for Übersicht can be written in either Javascript or Coffeescript. Continuing on the example monitoring your hard drive space, I wrote two widgets as an example in Javascript and Coffeescript. Both widgets were written to display the same information from the following shell command:

Coffeescript verson: Gist link

Pure Javascript version: Gist link

Here's a comparison of the output of the two scripts:

Widget Gallery

The makers of Übersicht also have a gallery of widgets other users have created and were willing to share.

Some other widgetsI'm looking at:

  • Sysmon Set: a whole set of widgets to monitor your system.
  • Pretty Weather: a stripped down version of the weather widget I'm currently using. Looking at replacing the predicted high temperature with the current temperature. [1]

Work in progress

I've moved over all my core GeekTool widgets to Übersicht and have started looking at some new ones too. Some progress pictures of my desktop as I've developed new or updated widgets for Übersicht.

Progress screenshot:

Additional progress screenshot:

  1. This has caused me to learn more about the forecast.io API than I ever thought possible. ↩

Comments from original WP Post:

Jason.Verly: You'll need to make some adjustments to the widget placement in the 'Style' section. For some reason all the widget creators liked the bottom right corner.

Jason.Verly: I have some screencasts set for later this fall. Entre amis 6th edition pdf.

CrazedLeper: Ok, I installed the app and the widgets but, is there a way to customize them? I can't find a way to move those that are overlapping and some are just plopped in the middle of my screen.

Jose Duran: Hi, Would it be possible to get a quick explanation as to how to customize in youtube ???? also what is the program should we use to make adjustments in style ???? as long as it is impossible to do it via Debug Console. Thanks a lot





broken image