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


Click here to return to the 'Modified script that makes iTunes play after everything is done' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Modified script that makes iTunes play after everything is done
Authored by: nosaj56 on Apr 23, '04 04:34:47PM

using terms from application "Mail"
-- This is what allows this AppleScript to run as a Rule
on run
--Performs the following action on each new mail received
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
-- See Mail's AppleScript dictionary for the full documentation on the
-- 'perform mail action with messages' handler.
tell application "iTunes"
--Pause iTunes to you can hear it what says next
pause
end tell
say "You have mail from"
set logString to "" & return
tell application "Mail"
set selCount to (count of selectedMsgs)
--A little bit of error handling
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 & ". "
if length of logString > 0 then
--note that you could have it speak the subject as well
say ":" & theSender
end if
--open the message in mail in a new window
open msg

end repeat
end tell
--open up mail to read the new messages
tell application "Mail"
activate
end tell

tell application "iTunes"
--Tell iTunes to play again
play
end tell

end perform mail action with messages
end using terms from



[ Reply to This | # ]
Modified script that makes iTunes play after everything is done
Authored by: Chris Biagini on Apr 25, '04 04:23:57PM

What if iTunes wasn't playing? Won't this modified version start playing music every time you get a new message?



[ Reply to This | # ]
You're right. Modify like this...
Authored by: Xeo on Apr 25, '04 10:29:38PM
You can just find out if iTunes is playing before you mess with it. Pause if it's playing, then play again when you're all done.
tell application "iTunes"
	set isPlaying to player state is playing
end tell

if isPlaying then
	tell application "iTunes" to pause
end if

-- later, after announcing the e-mail

if isPlaying then
	tell application "iTunes" to play
end if


[ Reply to This | # ]