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


Click here to return to the 'A very improved version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A very improved version
Authored by: momerath on Apr 25, '04 01:11:34AM
This version incorporates several improvements made by the above posters as well as an additional one: if there is new mail from several people, it will format it as a list and read it (e.g. for two emails, "You have mail from Bob and Joe," and for three, "You have email from Bob, Jane, and Joe.") The other improvements are: the iTunes fader works it checks to see if iTunes is open before touching it (thus avoiding opening it if it's not open or playing a song if one isn't playing) it doesn't activate the message (I got rid of the log stuff because it is unnecessary)
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

using terms from application "Mail"
	on perform mail action with messages selectedMsgs
		set reactivate to false
		tell application "System Events"
			set the process_flag to (exists process "iTunes")
		end tell
		if the process_flag then
			tell application "iTunes"
				if player state is playing then
					repeat
						set snd to sound volume of application "iTunes"
						if snd is less than or equal to 30 then
							exit repeat
						end if
						set sound volume of application "iTunes" to (snd - 10)
						delay 0.1
					end repeat
					set reactivate to true
				end if
			end tell
		end if
		
		set logString to "" & return
		set speakString to "You have mail from "
		tell application "Mail"
			set selCount to (count of selectedMsgs)
			repeat with counter from 1 to selCount
				set msg to item counter of selectedMsgs
				set theSender to sender of msg
				set theSender to extract name from theSender
				if length of theSender > 0 then
					if selCount > 1 and counter is selCount then
						set speakString to speakString & " and "
					end if
					set speakString to speakString & theSender
					if (selCount - counter) > 0 and selCount > 2 then
						set speakString to speakString & ", "
					end if
				end if
			end repeat
			set speakString to speakString & "."
			say speakString
		end tell
		
		if reactivate is true then
			tell application "iTunes"
				repeat
					set snd to sound volume of application "iTunes"
					if snd is greater than or equal to 100 then
						exit repeat
					end if
					set sound volume of application "iTunes" to (snd + 10)
					delay 0.1
				end repeat
			end tell
		end if
	end perform mail action with messages
end using terms from


[ Reply to This | # ]
A very improved version
Authored by: rarora-resume@ma on May 02, '04 12:12:54PM

this is a great script, i have a problem with it though. The volume for itunes gets maxed out everytime the script is run. How do I change so that it simplly goes back to the original volume state? If that's too much code, how about setting the volume to the middle?



[ Reply to This | # ]
A very improved version
Authored by: rarora-resume@ma on May 02, '04 12:34:41PM

okay so i got it set the volume to 50%, i got a little confused by the fader effect.

I'm still working on capturing the original volume(before the fade out). I would imagine it's pretty easy, I'm new to Apple script and macs too(just switched two weeks ago).



[ Reply to This | # ]
A very improved version
Authored by: rarora-resume@ma on May 02, '04 12:53:00PM

Okay, I figured it out :) I also changed the fader to fade in and out more gradually (+5, -5). It's seems like a smoother operation now.



[ Reply to This | # ]