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

Click here to return to the 'Enhanced, threaded version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Enhanced, threaded version
Authored by: Hugin777 on Mar 25, '04 08:51:58AM
  1. Get the big picture - if you get three mails from the same sender, John, it will simply say "New mail: three from John". If you get a lot of mail it will just say e.g. "New mail: from 6 different senders !"
  2. Threaded - does not block while announcing
  • New mail: from Michael.
  • New mail: From 3 different senders ! 2 from Erik. 3 junk. 1 from John.
  • New mail: From 5 different senders !

The script has to be saved as a Stay-open script, as it needs to monitor in the background. It will Quit itself when the announcement is done.

IMPORTANT: You need to save the script as a program, and check "Stay open" !

property announceJunk : false -- should junk mail be announced too ?
property senderCntThreshold : 2 -- more than this, and the count is announced
property senderCntMax : 4 -- more than this, and only the count is announced
property voiceVolume : "0.7"

property senderList : {}
property firstRun : true -- don't do anything at first run of idle

using terms from application "Mail"
	on perform mail action with messages theMessages
		repeat with thisMessage in theMessages
			set thisSender to extract name from sender of thisMessage
			set junk to junk mail status of thisMessage
			tell application "Mailmelding"
				-- We have to run ourselves :-/
				--  If we didn't use "tell" the run method would never be called...
				newMail(thisSender, junk)
			end tell
		end repeat
	end perform mail action with messages
end using terms from

on newMail(thisSender, junk)
	if junk then
		if not announceJunk then
		end if
		set thisSender to " junk "
	end if
	set found to false
	repeat with x in my senderList
		if sender of x is equal to thisSender then
			set cnt of x to (cnt of x) + 1
			set found to true
			exit repeat
		end if
	end repeat
	if not found then
		copy {sender:thisSender, cnt:1} to end of my senderList
	end if
end newMail

on idle
	if firstRun then
		set firstRun to false
		return 2
	end if
	tell application "Mail"
		set mailIdle to background activity count = 0
	end tell
	if mailIdle then
		set senderCount to count of senderList
		if senderCount = 0 then
			set firstRun to true
			return 0
		end if
		set sayStr to "[[volm " & voiceVolume & "]]" & "New mail:" & space
		if senderCount > senderCntThreshold then
			set sayStr to sayStr & "From " & senderCount & " different senders !" & space
		end if
		if senderCount is less than or equal to senderCntMax then
			--  Report the findings
			repeat with x in senderList
				set thisSender to sender of x
				set cnt to cnt of x
				set sayStr to sayStr & spokenPrefix(senderCount, cnt) & space
				if thisSender is " junk " then
					set sayStr to sayStr & "junk." & space
					set sayStr to sayStr & "from " & pickFirstPart(thisSender) & "." & space
				end if
			end repeat
		end if
		say sayStr
		set senderList to {}
		set firstRun to true
	end if -- mailIdle
	return 2 -- Call again every 2 seconds...
end idle

on spokenPrefix(senderCount, cnt)
	if senderCount = 1 and cnt = 1 then
		return ""
		return (cnt as text)
	end if
end spokenPrefix

on pickFirstPart(emailOrName)
	set oldDelim to AppleScript's text item delimiters
	if emailOrName contains "@" then
		set AppleScript's text item delimiters to {"@"}
		set AppleScript's text item delimiters to {" "}
	end if
	return first text item of emailOrName
	set AppleScript's text item delimiters to oldDelim
end pickFirstPart

[ Reply to This | # ]
Correction !!!!
Authored by: Hugin777 on Mar 25, '04 09:07:39AM
Whoops, you have to change the string "Mailmelding" to the name you choose for the script !

If you save the script as "Mail-announcer", then change this line:

tell application "Mailmelding"

to this:

tell application "Mail-announcer"

[ Reply to This | # ]
Enhanced, threaded version
Authored by: mikeall on Mar 29, '04 02:18:24AM

I tried to cut and paste this one and make it into an apple script but it won't compile in Jaguar using Script Editor 1.9.
The error says:
Expected "given", "into", "with", "without" or other parameter name but found identifier.

The script looks like it would be great so any help will be appreciated.


[ Reply to This | # ]
Enhanced, threaded version
Authored by: Hugin777 on Apr 18, '04 10:25:45AM

Sorry, I'm no AppleScript expert. It works in Panther as far as I know...

[ Reply to This | # ]