Read New Mail Message

Hi there,

i want to make a script which is being executed everytime a new mail gets in. It should read the mail via speech.
In Mail Rules i set up every mails with “@” in their name. So its being loaded every time a mail comes in, not a problem.
But now the script makes me some problems. I first decided to take the AppleScript “Speak Sender and Subject” which works fine for me. But i dont get the script speaking the message too. Here is the Script:


using terms from application "Mail"
	on perform mail action with messages selectedMsgs
		-- See Mail's AppleScript dictionary for the full documentation on the
		-- 'perform mail action with messages' handler.
		set logString to "" & return
		tell application "Mail"
			set selCount to (count of selectedMsgs)
			if selCount is equal to 0 then
				set logString to logString & "There are no selected messages."
			else if selCount is equal to 1 then
				set logString to logString & "There is " & selCount & " selected message."
			else if selCount > 1 then
				set logString to logString & "There are " & selCount & " selected messages."
			end if
			repeat with counter from 1 to selCount
				set msg to item counter of selectedMsgs
				set theSubject to subject of msg
				set theSender to sender of msg
				set theSender to extract name from theSender
				set logString to (logString & tab & "Message " & counter as string) & " from: " & theSender & ", subject: " & theSubject & ".  "
			end repeat
		end tell
		if length of logString > 0 then
			say logString
		end if
	end perform mail action with messages
end using terms from

-- If run as an ordinary script, instead of directly from the Scripts
-- menu, it will call the default handler instead.
using terms from application "Mail"
	on run
		tell application "Mail" to set sel to selection
		tell me to perform mail action with messages (sel)
	end run
end using terms from

Thanks for help in advance

Model: Powerbook G4 1.67Ghz
AppleScript: 2.1.1
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

Nice script, thanks. I needed to make only 2 changes to your code so that it “spoke” completely.


using terms from application "Mail"
	on perform mail action with messages selectedMsgs
		-- See Mail's AppleScript dictionary for the full documentation on the
		-- 'perform mail action with messages' handler.
		set logString to "" & return
		tell application "Mail"
			set selCount to (count of selectedMsgs)
			if selCount is equal to 0 then
				set logString to logString & "There are no selected messages."
			else if selCount is equal to 1 then
				set logString to logString & "There is " & selCount & " selected message."
			else if selCount > 1 then
				set logString to logString & "There are " & selCount & " selected messages."
			end if
			repeat with counter from 1 to selCount
				set msg to item counter of selectedMsgs
				set theSubject to subject of msg
				set theSender to sender of msg
				set theContent to content of msg
				set theSender to extract name from theSender
				set logString to (logString & tab & "Message " & counter as string) & " from: " & theSender & ", subject: " & theSubject & ".  " & theContent
			end repeat
		end tell
		if length of logString > 0 then
			say logString
		end if
	end perform mail action with messages
end using terms from

-- If run as an ordinary script, instead of directly from the Scripts
-- menu, it will call the default handler instead.
using terms from application "Mail"
	on run
		tell application "Mail" to set sel to selection
		tell me to perform mail action with messages (sel)
	end run
end using terms from