This outputs just the count of new messages in your inbox in gmail. Though not particularly unique, the really nice thing about this script is that it DOESN'T require you to put your username and password into the script. It automatically retrieves in from a keychain. So even while using this script you're USER/PASS are still protected by Mac's keychain service.
This script also does NOT require mail to be open for it to work, unlike some others.
[Admin note: I had to make a few changes to the script to make it work. Here is my version, which is the one used in the downloadable geeklet below.]
password=`security 2>&1 >/dev/null find-generic-password -gl "Google Service: Google Notifier" | grep -m 1 "password" | sed -e 's/password: "//' | sed -e 's/"//'`
username=`security find-generic-password -l "Google Service: Google Notifier" | grep -m 1 "acct" | sed -e 's/ "acct"<blob>="//' | sed -e 's/"//' | sed -e 's/@/%40/'`
label='inbox'
url=`echo "https://$username:$password@mail.google.com/mail/feed/atom/$label" | sed 's/ //g'`
THE_COUNT=`curl --silent "$url" | grep -m 1 "fullcount" | sed -e 's/<fullcount>//' | sed -e 's/</fullcount>//'`
echo "$THE_COUNT"
For reference, here is the original script:
# Thanks to Dave Taylor at www.askdavetaylor.com for the great tutorial on accessing and parsing RSS feeds with a shell script
# Provide your log in credentials
# NOTE - you MUST replace the @ in your username email with %40 or the scrip will fail
password=`security 2>&1 >/dev/null find-generic-password -gl "Google Service: Google Notifier" | grep -m 1 "password" | sed -e 's/password: "//' | sed -e 's/"//'`
username=`security find-generic-password -l "Google Service: Google Notifier" | grep -m 1 "acct" | sed -e 's/ "acct"="//' | sed -e 's/"//' | sed -e 's/@/%40/'`
# Set the label that you want use
label='inbox' # the GMail label that contains the email you want to display
url='https://'"$username"':'"$password"'@mail.google.com/mail/feed/atom/'"$label" # GMail users
# Finds the one line that lists the full count of messages in your inbox and then trims
# off the preceding "" and proceeding ""
THE_COUNT=`curl --silent "$url" | grep -m 1 "fullcount" | sed -e 's///' | sed -e 's///'`
echo "$THE_COUNT" # Print the count to the screen