Vote
Bury
12
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

Geeklet file(s) to download

gmailunread.glet

Either right-click and choose "Save Linked File As..." or hold the Option key and click to download files.
If using Safari, you may have to rename the files without the extra .txt extension that is added.

Comments


Written by radil
129 days ago
It's not working for me... Do I need google notifier installed in my mac?



Written by hongyi2008
40 days ago
the maybe is key error,after i am change "security 2>&1 >/dev/null find-internet-password -gl "www.google.com" ", it 's ok.



Log in to comment or register here.