Keep an eye on your single or multiple gmail inboxes.

Unread email counters will help you save time on constantly checking your inboxes.

Posted by Gediminas Siutilas on November 27, 2014

Preface

In case you're using only web interface for your GMail accounts then that's the script specially designed for you. Having unread email counters on your OSX status bar you are free from tabs opened in your browser and regular checks for new emails going to the GMail page itself.

* If you downloaded ShellWrangler app this scripts will be packed along with the downloaded application.

Configuration

Single inbox to monitor

In order to track unread email count for a single gmail inbox you need to configure script as follow.

Script configuration:
#@@@{User name}
username=%user name%

#@@@{Password or app key}
password=%password%

...

run() {
	checkInbox $username $password
}

In case you have 'Apps passwords' enabled at your gmail account you need to use them in order to have successful authentication for this script.

Multiple inboxes to monitor

If you have multiple GMail accounts you want to track configuration of the script follow:

Script configuration:
run() {
	checkInbox $username $password
	drawSeparator
	checkInbox $username2nd $password2nd
	drawSeparator
	checkInbox $username3rd $password3rd
}

Where '$username2nd', '$username3rd' can be hardcoded to method 'run' itself or you can expose them through the shell variables as it's done based per provided example

'drawSeperator' function inserts a diamond (🔸) in between the unread email indicators.

Script:

Download
#!/bin/bash

#   ____ __        __ __ _      __                       __         
#  / __// /  ___  / // /| | /| / /____ ___ _ ___  ___ _ / /___  ____
# _\ \ / _ \/ -_)/ // / | |/ |/ // __// _ `// _ \/ _ `// // -_)/ __/
#/___//_//_/\__//_//_/  |__/|__//_/   \_,_//_//_/\_, //_/ \__//_/   
#                                               /___/               
#                            _ __  __      _ _ 
#  _  _ _ _  _ _ ___ __ _ __| |  \/  |__ _(_) |
# | || | ' \| '_/ -_) _` / _` | |\/| / _` | | |
#  \_,_|_||_|_| \___\__,_\__,_|_|  |_\__,_|_|_|
#                                              
# Script author: gadominas@gmail.com
# 
#$$${ Counter for unread GMail emails. You can configure multiple inboxes to monitor. }                                                                                                                                                                

#@@@{User name}
username=%username%
username2nd=%username%
username3rd=%username%

#@@@{Password or app key}
password=%password%
password2nd=%password%
password3rd=%password%

checkInbox() {	
	unreadCount=$(/usr/bin/curl -su \
	 $1:$2 https://mail.google.com/mail/feed/atom |  \
	 grep -o '\w*' | \
	 sed -e 's///' )
	
	if [ ! -z "$unreadCount" -a "$unreadCount"!=" " ];
		then {
			printf "📭|%s" $unreadCount			
		} else
			## in case of empty weather output (connection timeout)
			printf "?!"
	fi	
}

drawSeparator() {
	printf "%s" "🔸"
}

run() {
	checkInbox $username $password
	drawSeparator 
	checkInbox $username2nd $password2nd
	drawSeparator 
	checkInbox $username3rd $password3rd
}

run