Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Use GeekTool to see new Mail messages on the desktop Apps
I use GeekTool a lot, and one of the things I use it for is to display my new email messages on the desktop. To do that, I use this AppleScript: In GeekTool, I created a new entry and set the pop-up to Shell. On the Command tab, I entered the command as osascript /path/to/mailcheck.scpt (replace with the path and name of your own AppleScript).

This works well for me, though I am sure it could be made a little more useful by others. It was my first AppleScript -- what a strange language!
    •    
  • Currently 3.22 / 5
  You rated: 4 / 5 (9 votes cast)
 
[28,306 views]  

Use GeekTool to see new Mail messages on the desktop | 11 comments | Create New Account
Click here to return to the 'Use GeekTool to see new Mail messages on the desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use GeekTool to see new Mail messages on the desktop
Authored by: daeley on Mar 31, '09 08:20:34AM
A few years back I used GeekTool to do something similar, grabbing both Mail.app and NetNewsWire's current unread counts and displaying them in a mini-monitor window:

http://www.celsius1414.com/mini-monitor

And here's an iTunes monitor as well:

http://www.celsius1414.com/itunes_monitor

[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: mainmode1 on Mar 31, '09 10:29:23AM
Slight improvement to number msg's and check unread count before looping:

set newline to ASCII character 10 
set finalText to "" 
 tell application id "com.apple.mail" 
  set unreadCount to (get unread count of inbox) 
  if unreadCount > 0 then 
    set theMessages to (messages of inbox whose read status is false) 
    repeat with i from 1 to number of items in theMessages 
      set thisMessage to item i of theMessages 
      set fromMsg to (sender of thisMessage as string) 
      set subjMsg to (subject of thisMessage as string) 
      set finalText to finalText & i & ". " & fromMsg & newline & "      " & subjMsg & newline
    end repeat 
  else 
    set finalText to "No mail." 
  end if 
end tell 
finalText 


[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: MG_ on Mar 31, '09 11:34:33AM

Has GeekTool been fixed from its sleep issues?



[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: logo on Apr 01, '09 08:14:00AM
I can't even get GeekTool to run on 10.5.6 and a MacBook Pro.

When opening the PrefPane I get an error, that the preferences "cannot be edited on intel machines" or even a "cannot be opened".

I searched quite a bit on the web and found patched versions like the jaw-Patch, or (http://infinite-sushi.com/2006/02/intel-build-of-geektool/) but no success.

Anyone here who can lead me to a working download?

Thanks

[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: ppp on Mar 31, '09 11:43:29AM
I really like the plugin Mail.appetizer, that does this with Growl. You can get it here:

http://www.bronsonbeta.com/

[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: chris79 on Mar 31, '09 01:09:42PM

i recently wrote the same sort of script, but for Gmail. the code may be inefficient, or just plain bad, but it works. improvements are very welcome!

it uses /usr/bin/security to get the account password(s) from the Keychain, so you'll see a security popup that asks for permission first. i set mine to "Always Allow" so that i don't have to give it permission every time it checks (i set mine to 1-minute intervals).

here's the (perl) code:


#!/usr/bin/perl

use strict;

# accounts ("label"=>"username")
my %accounts = ("Work"=>"work\@myGoogleAppsDomain.com","home"=>"GmailUsername","alternate account"=>"alternateEmail\@gmail.com");

# max messages per account (0 for unlimited)
my $max_count = 4;

# max message line length (0 for unlimited)
my $max_line_length = 40;

# set your curl location
my $curl = "/usr/bin/curl";

####################################
# don't mess with these, please :) #
####################################
my @usernames = values(%accounts);
my @account_labels = keys(%accounts);
my @passwords;
my @appsDomain;
my $feedURL;
my $RSSfeed;
my $output;
my $i = 0;

foreach (@usernames){
	# set and reset these variables
	my $new_mail_count;
	my $temp_val = '';
	my $max_c = $max_count;
	$RSSfeed = '';
	my @names;
	my $firstAuth;
	my $lastAuth;
	
	# is this a regular Gmail or a Google Apps account? (also, try to find "@" character (unicode 0040))
	if (@usernames[$i] !~ m/\x{0040}/i || @usernames[$i] =~ m/\x{0040}gmail\.com/i) {
		$feedURL = "https://mail.google.com/mail/feed/atom";}
	else {
		@appsDomain = split(/\x{0040}/,@usernames[$i]);
		$feedURL = "https://mail.google.com/a/@appsDomain[1]/feed/atom";}

	# get the password for the account
	my @pass = split("\"",`security 2>&1 >/dev/null find-internet-password -ga @usernames[$i]`);
	
	# get the RSS feed
	chomp($curl,@usernames[$i],@pass[1],$feedURL);
	$RSSfeed = `$curl -s -u @usernames[$i]:@pass[1] $feedURL 2>/dev/null`;
	
	# get number of new messages
	$new_mail_count = $RSSfeed; $new_mail_count =~ s/.*<fullcount>//sig; $new_mail_count =~ s/<\/fullcount>.*//sig;
	
	# determine how many new messages to use
	if ($new_mail_count < $max_c || $max_c == 0) {$max_c = $new_mail_count;}
	
	# get the new messages
	$output .= @account_labels[$i]." - ".$new_mail_count." New message";
	if ($new_mail_count == 1) {$output .= "\n";} else {$output .= "s\n";}
	
	#split up the entries
	my @entries = split(/<entry>/sim,$RSSfeed);
	foreach (@entries) {
		# for each good entry match
		if ($_ =~ m/<name>/ && $_ =~ m/<title>/) {
			# get the authors' names...
			my $names = $_; $names =~ s/.*<name>/>/ig; $names =~ s/<\/name>.*//ig;
			
			# strip tags and newlines and dump names into an array
			$names =~ s/<.*>//ig; $names =~ s/\n//ig; @names = split(">",$names); shift(@names);
			
			# format author names the same way Gmail does
			if (scalar(@names)==1) {$names = @names[0];}
			else {
				$firstAuth = @names[scalar(@names)-1]; $firstAuth =~ s/(^.*)\ (.*$)/$1/ig;
				$lastAuth = @names[0]; $lastAuth =~ s/(^.*)\ (.*$)/$1/ig;
				if (scalar(@names)==2) {$names = $firstAuth.", ".$lastAuth;}
				else {$names = $firstAuth." .. ".$lastAuth;}
			}
			
			# get subject
			my $subject = $_; $subject =~ s/.*<title>//sig; $subject =~ s/<\/title>.*//sig;
			if ($subject eq '') {$subject = "(no subject)";}

			# stick names and subject together
			my $line = "  ".$names." - ".$subject;

			# replace quote encodings with sane characters
			$line =~ s/\&\#39;/'/g; $line =~ s/\&\#34;/"/g;
			
			# limit line length
			if ($max_line_length > 0 && length($line) > $max_line_length) {$line = substr($line,0,$max_line_length)."...";}

			# and add it to the output
			$output .= $line."\n";

			# stop at the maximum desired count
			$max_c--;
			if ($max_count > 0 && $max_c == 0) {last;}
		}
	}
	# increment loop counter
	$i++; 
}

# kill this line or modify it you want. it's not necessary.
# it just keeps everything tacked to the bottom of my
# GeekTool block by printing blank lines.
my @temp = split("\n",$output); my $line_count = scalar(@temp); while ($line_count < (($max_count*scalar(@usernames))+scalar(@usernames))) {printf "\n";$line_count++;}

# print it all out!
printf $output;



[ Reply to This | # ]
EDIT
Authored by: chris79 on Apr 01, '09 06:36:29AM

EDIT

i just changed these lines in the author name section (lines 77 & 78):


$firstAuth = @names[scalar(@names)-1]; $firstAuth =~ s/\ .*$//ig;
$lastAuth = @names[0]; $lastAuth =~ s/\ .*$//ig;

that should trim down to just the first name.



[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: parraccourci on Apr 01, '09 05:02:10AM
In case you don't want Mail to be lunched every time the script is executed by GeekTool, use this script:
set newline to ASCII character 10
tell application "System Events" to set iCalIsRunning to (name of processes) contains "Mail"
set finalText to ""
if iCalIsRunning then
	tell application id "com.apple.mail"
		set unreadCount to (get unread count of inbox)
		if unreadCount > 0 then
			set theMessages to (messages of inbox whose read status is false)
			repeat with i from 1 to number of items in theMessages
				set thisMessage to item i of theMessages
				set fromMsg to (sender of thisMessage as string)
				set subjMsg to (subject of thisMessage as string)
				if subjMsg = "" then
					-- do something really important here
					
				else
					set subjMsg to newline & "     " & subjMsg
				end if
				set finalText to finalText & i & ". " & fromMsg & subjMsg & newline
			end repeat
		else
			set finalText to "No new mail"
		end if
	end tell
else
	set finalText to "Mail not open"
end if
finalText


[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: mv123 on Jun 27, '09 02:12:33AM

Hi! Thanks for the hints.
When I try this it gives me the Unread count of the Inbox. Is there a way to get unread count of all mailboxes as I have Rules applied to my Mail app. I have set my Dock count to give Unread in all boxes but not able to replicate that in the script.
Thank you



[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: Emeraldscorpion on Aug 20, '09 08:01:54AM
I've written this applescript:
tell application "System Events" to set iCalIsRunning to (name of processes) contains "Mail"
set finalText to ""
if iCalIsRunning then
	tell application "Mail"
		set unreadCount to unread count of inbox
		if (unreadCount is greater than or equal to 1) then
			return (unreadCount as string) & " new messages"
		else
			set finalText to "No new Mail"
		end if
	end tell
	
else
	set finalText to "Mail not open"
end if 
It tells you how many unread Mail there are / That there is no Mail / Mail is not open. I stiched this together from different people's scripts :P

[ Reply to This | # ]
Use GeekTool to see new Mail messages on the desktop
Authored by: bglnelissen on Apr 25, '13 04:51:31AM
I also use a combination of BASH and AppleScript. Here my bash script that returns my flagged mail and my unread mail. It uses sed to color the mails by their flag.

#!/bin/bash
# b.nelissen

# list unread mails using applescript
UNREAD=$(osascript -e '
set newline to ASCII character 10
set finalText to newline
set previousRowMsg to ""
tell application "Mail"
	-- check for unread mail
	set newMessages to (every message in inbox whose read status is false)
	if the (count of newMessages) is greater than or equal to 1 then
		set n to (count of newMessages)
		repeat with i from 1 to number of items in newMessages
			set thisMessage to item i of newMessages
			set fromMsg to (sender of thisMessage as string)
			set subjMsg to (subject of thisMessage as string)
			set rowMsg to word 1 of fromMsg & ": " & subjMsg
			-- fix duplicate output.
			if rowMsg is not equal to previousRowMsg then
				set finalText to finalText & rowMsg & newline
			end if
			set previousRowMsg to rowMsg
		end repeat
	end if
end tell
finalText
')

# list flagged mails using applescript
FLAGGED=$(osascript -e '
set newline to ASCII character 10
set finalText to newline
set previousRowMsg to ""
set flag to ""
tell application "Mail"
	-- check for flagged mail
	set flaggedMessages to (every message in inbox whose flagged status is true)
	if the (count of flaggedMessages) is greater than or equal to 1 then
		set n to (count of flaggedMessages)
		repeat with i from 1 to number of items in flaggedMessages
			set thisMessage to item i of flaggedMessages
		    set flag to flag index of thisMessage
			set fromMsg to (sender of thisMessage as string)
			set subjMsg to (subject of thisMessage as string)
			set rowMsg to word 1 of fromMsg & ": " & subjMsg
			-- fix duplicate output.
			if rowMsg is not equal to previousRowMsg then
			    -- add this mail to previous ones and add a dot (needed for sed to make colours)
				set finalText to finalText & flag & rowMsg & "." & newline
			end if
			set previousRowMsg to rowMsg
		end repeat
	end if
end tell
finalText
')

# Color codes for each flag. Codes [0-6] are defined by Mail
esc=`echo -en "\033"` # escape code
# Set colors
cc_0="${esc}[0;31m" # red AND grey
cc_1="${esc}[0;36m" # orange
cc_2="${esc}[0;33m" # yellow
cc_3="${esc}[0;32m" # green
cc_4="${esc}[0;34m" # blue
cc_5="${esc}[0;35m" # purple

# Present mail
if [ "$FLAGGED" != "" ]; then
    echo -e "Flagged:""\033[0m""$FLAGGED" | sed 's/^[0]/'$(echo $cc_0)'/g;s/^[1]/'$(echo $cc_1)'/g;s/^[2]/'$(echo $cc_2)'/g;s/^[3]/'$(echo $cc_3)'/g;s/^[4]/'$(echo $cc_4)'/g;s/^[5]/'$(echo $cc_5)'/g;s/^[6]/'$(echo $cc_6)'/g;s/\.$/'$(echo -e "\033[0m")'/g' 
fi
if [ "$UNREAD" != "" ]; then
    echo -e "Fresh:""$UNREAD"
fi
if [ "$UNREAD" == "" ] && [ "$UNREAD" == "" ]; then
    echo "You're all done."
fi
Edited on Apr 25, '13 04:52:18AM by bglnelissen


[ Reply to This | # ]