This is the little brother in the Geeklet family, but very powerfull. If you are not happy with the Script Geeklet, Web will unleash your creativity. It works the same way, but instead of just text, you display a full web page, or generate your own HTML code using your own script. GeekTool by Tynsoe.org is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. Implementing the Script as a Geeklet. Once you're finished coding, save out this script in your Geeklets folder. Now go back to GeekTool and drag out a new shell Geeklet. In the Command field, type 'osascript' followed by a space and the path to wherever you place the script. Here's what my command looks like.
June 27, 2009 at 9:52 PM by Dr. Drang
Update 7/29/09
The current
The current
pywapi.py
, version 0.2.1, has the bug fix described in this post, so there’s no need to edit it. Just install it as is using setup.py
, and the weathertext
script will work fine.I like having GeekTool display the current weather on my desktop, and I’ve written a script that gets the information from a NOAA website and formats it for GeekTool. Now there’s a new Python weather library, called
pywapi
, that simplifies the process of getting the data and extends it beyond just NOAA’s weather stations. I’ve rewritten my GeekTool script to use this new library.The
pywapi
library is the creation of Eugene Kaznacheev. It provides a simple Pythonic interface to weather data supplied byGoogle doesn’t have a weather page, per se, but it does provide weather info through an API. The Gismeteo service is in Russian, so I can’t give any advice on using it.
The current version of
pywapi
, version 0.2.0, has a bug that causes it to fail when accessing NOAA data. Fortunately, this bug is easy to fix before installation. I’ve described the bug and provided my fix on the pywapi
Issues page—perhaps the fix will be rolled into the official pywapi
distribution soon. Until then, follow these instructions to get a working version of pywapi
:Download the tarball to a convenient location and extract the code. Open the
pywapi.py
file and scroll to the bottom of the get_weather_from_noaa
function. Change this codeto this
The original code only works if NOAA is returning every bit of information in the
data_structure
tuple. As it turns out, sometimes NOAA stations don’t report wind gust, wind chill, or heat index values. In those situations, the original code fails when the get_weather_from_noaa
function is called. The revised code succeeds regardless of whether the data are reported or not.After saving the edited file, execute
from the command line, give your administrator password at the prompt, and the
pywapi
library will be installed in /Library/Python/2.5/site-packages
directory.To see what kind of data are available from the different services, open the
examples
directory in the pywapi
distribution and try them out. Here’s pywapi-google-example.py
, modified to return values for my town rather than New York:The modification is on Line 5, where I’ve changed the argument to my zip code. The output looks like this
Geektool Mac Scripts
It’s a multi-level dictionary, from which you can pluck the current conditions and the forecast for the next few days.
Similarly, if I modify
pywapi-yahoo-example.py
toin which the arguments in Line 5 have been changed to my zip code and an empty string to give the Naperville results in US customary units. Running this example script yields
which is another multi-level dictionary with similar information. Yahoo! gives sunrise and sunset times, which Google doesn’t, but Yahoo’s forecasts only include today and tomorrow.
Here’s
pywapi-noaa-example.py
after my modification:The argument in Line 5 is the code for the NOAA station at the Aurora airport west of Naperville. Finding the best NOAA station isn’t as easy as just entering your zip code, but if you go to this NOAA page, you can find it pretty quickly.
The output from
pywapi-noaa-example.py
iswhich is a simple dictionary with only current conditions, no forecasts. Still, I like the NOAA data set because it includes, when appropriate, the wind gust speed and heat index, items that neither Google nor Yahoo! provide.
So here’s my new GeekTool weather script, called
weathertext
:At the moment, it’s basically a rewrite of my previous GeekTool weather script, using the clean
pywapi
calls instead of a kludgy series of regular expressions to pull the desired information out of the NOAA results. I’ll probably add to it, gathering bits from the Google or Yahoo! results and mixing them into the output. I have GeekTool set up to display the output of weathertext
—which I’ve made executable and keep in a “bin” directory in my home folder—in the lower left corner of my screen.I have the temperature at the bottom because it’s the most important item and putting it at the bottom makes it the most likely to be visible.
Update 7/2/09
I’ve made some minor changes to
Published on 11 Jan 2010 · Filed in Explanation · 451 words (estimated 3 minutes to read)I’ve made some minor changes to
weathertext
since writing this post. Rather than updating the post every time I make a change, I’ve set up a GitHub repository where you can always download my latest version.I’ve been experimenting with GeekTool, a nifty Mac OS X Preference Pane that allows you to display information on your desktop. This information can be static text, images, or the output of a script. The last option is the most useful one, in my opinion, and that’s where I’ve been putting GeekTool to use for me. This isn’t going to be some long post on how to use GeekTool or why you should install it; rather, I just wanted to share a couple of short scripts that I wrote that you might find useful.
I use Mac OS X’s network location support extensively. I have separate locations for home (where I have a proxy server) and when I’m out and about (where there generally is no proxy server). So it’s important for me to be able to tell, quickly, which location is active. If the wrong location is active, then network connectivity is impaired.
To help, I use this command with GeekTool to display the network location on my desktop:
Note that if you are running as an administrative user on your Mac (which I don’t in order to reduce potential security risks), then the
networksetup
command I use above will probably behave differently for you. Since I’m not running as an administrative user, networksetup
would throw an error at the command line. Thus why I had to redirect STDERR to STDOUT and filter it using tail
. Now, a quick F11 to show the desktop and I can immediately see which network location is active.I also recently added a script to show me what proxy servers are currently active. This is in anticipation of starting my new job at EMC. I don’t know if they have proxy servers on their network, but in the event they do I thought this next command might be handy:
This command displays the HTTP proxy host configured in your network settings. So, again, a quick F11 allows me to see which proxy hosts are configured and active on my Mac.
I actually wrapped several of these commands together into a shell script that you can download here if you’d like. I’m sure there is probably some bash black magic that could produce this output in a more efficient way; feel free to post suggestions for improvement if you have any!
Of course, I also have a few other scripts running with GeekTool—one that displays system information, one that produces IP addresses and Airport (wireless LAN) information, etc.—but these two are probably most useful to me so far.
![Geektool Scripts Geektool Scripts](https://www.tynsoe.org/v2/geektool/images/gt_shell.png)
Metadata and Navigation
Geektool Scripts Date
Be social and share this post!
Related Posts
![Geektool Scripts Geektool Scripts](/uploads/1/1/8/3/118386006/788016913.jpg)
Geektool Scripts Calendar
- Apparently, I'm Ahead Too21 Oct 2007
- Listing All Unique MailTags Keywords24 Aug 2007
- Listing Unique Projects Used by MailTags23 Aug 2007