Recently the folks over at Panic announced a cool new way to display critical stats on your desktop – Statoo. Like GeekTool, Statoo can put the weather, date, time, disk space, current song, and so on on your desktop. Unlike GeekTool, they do it all in a few clicks. Even more interesting was the ability to put email on the desktop. I hadn’t yet seen that done with GeekTool.
Intrigued by the email portion, I set out to have GeekTool display the most resent messages from my GMail inbox. This requires a little script fu, but not that much. Here’s what it looks like on my desktop.
The word “EMail is something I add as a header to this GeekTool module. Next, emails are displayed as the subject line first then below and indented slightly, the first few words from the body of the email. In the example above, the first email is my schedule from GCal. Since I’m writing this on a Sunday, I don’t have any events and the body is empty. The second email is some spam that GMail managed to miss. Then there is my reminder from Vitalist.com and so on.
To make this script work, we take advantage of the fact that GMail conveniently provides Atom feeds for any of your labels. You can access your feeds at https://mail.google.com/mail/feed/atom/<label name> where <label name> is the name of the label that you want to access. To access the feed for the inbox, we can take advantage of GMail’s built in “inbox” label. So the URL to access the feed for the inbox is https://mail.google.com/mail/feed/atom/inbox. This also works for Google Apps users. The URL is https://mail.google.com/a/<your company domain>/feed/atom/<label name> where <your company domain> is web domain that you use with Google Apps and as above <label name> is the label that you want to access. So the URL to access the feed for the inbox of a Google Apps user with a domain of somecompany.com is https://mail.google.com/a/somecompany.com/feed/atom/inbox.
OK, on to the script. I built the script with just a few variables for you to change. I’ve listed it below but you can download the complete script here.
# Thanks to Dave Taylor at http://www.askdavetaylor.com for the great tutorial on accessing and parsing RSS feeds with a shell script
echo “EMail” # Puts the word “Email” at the top for a header to the module
# Provide your log in credentials
# NOTE – you MUST replace the @ in your username email with %40 or the script will fail
username=’user%40gmail.com’ # username is your email address with @ replaced by %40. For Google Apps users this will be user%40yourcompany.com
password=’password’ # your password
# Set the label that you want use
label=’inbox’ # the GMail label that contains the email you wnat to display
#Set the Wdith of the output
width=’45’ # The number of columns wide that you want the output
# Required for Google Apps users
domain=’yourcompany.com’ # Your company domain – only needed for Google Apps users
# If you are using Google Apps put a # at the beginning of the first url= line and remove it from the second url line.
url=’https://'”$username”‘:'”$password”‘@mail.google.com/mail/feed/atom/'”$label” # GMail users
#url=’https://'”$username”‘:'”$password”‘@mail.google.com/a/'”$domain”‘/feed/atom/'”$label” # Google Apps users – remember to edit your organization’s domain in domain variable above
# Do not modify below this line
if [ $# -eq 1 ] ; then
headarg=$(( $1 * 2 )) # $(( )) specifies that you’re using an equation
headarg=”-8″ # default is four email messages
curl –silent “$url” | grep -E ‘(title>|summary>)’ | \
sed -n ‘2,$p’ | \
sed -e ‘s/<title>//’ -e ‘s/<\/title>//’ -e ‘s/<summary>/ /’ \
-e ‘s/<\/summary>//’ | \
head $headarg | fmt -w “$width”
Once you have modified the file with your information, save it to a location with the name gmail.sh. I use a GeekTool folder inside my Documents folder. Then you will have to make the script executable. To do that, assuming you saved the file as above, open the terminal and enter
chmod +x ~/Documents/GeekTool/gmail.sh
While you are still in the Terminal, to see if everything is working, try running the script by entering
If you’ve done everything right, you should see the subject lines and a summary of the body for first 4 messages from your inbox listed in the terminal.
Once you’ve saved the file and added the execution permissions, we can now go over to GeekTool. Open System Preferences and select the GeekTool module. Then click on the button for a new entry and select Shell as the entry type. The enter the command to run the script file in the command box
The script is set to take an argument for how many messages you would like to see. It will default to 4 messages, but you can alter that by putting a dash followed by a number at the end of the command. For example if I want to see 10 messages instead of 4 the command would be
sh ~/Documents/GeekTool/gmail.sh -10
You can see the GeekTool set up in the picture below.
That’s it! adjust the GeekTool settings to your liking or to match your awesome desktop and enjoy. I look forward to seeing GMail on the desktops featured Lifehacker from the Flickr Lifehacker Desktop Show and Tell pool.