#!/bin/bash
date
echo "Checking mail"
osascript -e 'tell application "Mail" to check for new mail'
inbox=$(osascript -e 'tell application "Mail" to unread count of mailbox "INBOX" of accounts')
echo "INBOX: $inbox unread"

names=$(osascript -e 'tell application "Mail" to name of mailboxes')
unread=$(osascript -e 'tell application "Mail" to unread count of mailboxes')

# remove commas and replace spaces in names with underscores
names=$(echo $names | sed 's/, /,/g' | sed 'y/, / _/')
unread=$(echo $unread | sed 's/, /,/g' | sed 'y/, / _/')

# put the unread numbers in $1,$2,$3 etc
set -- $unread

# run through the names and pull out the unread number for that name
for name in $names
do
	num=$1
	shift
	echo "$name: $num unread"
done
