Ett första utkast:
set theTime to getReadableTime(current date)
tell application "Mail"
check for new mail
set goodmorningText to "Goodmorning! The time is " & theTime & "."
say goodmorningText using "Whisper"
delay 2
repeat with thisAccount in every account
set thisInBox to mailbox named "INBOX" of thisAccount
set thisUnreadCount to unread count of thisInBox
if thisUnreadCount is not 0 then
set unreadMessages to (messages of thisInBox whose read status is false)
if thisUnreadCount > 1 then
set pluralText to "s"
else
set pluralText to ""
end if
set speechCountText to "You have " & thisUnreadCount & " unread message" & pluralText & "."
-- & " in " & (name of thisAccount) & "."
say speechCountText
repeat with i from 1 to number of items in unreadMessages
set thisMessage to item i of unreadMessages
set theSender to sender of thisMessage
set savedTextItemDelimiters to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {"<"}
set realName to (first text item of (theSender as string))
--finally, reset the text item delimiters:
set AppleScript's text item delimiters to savedTextItemDelimiters
on error m number n from f to t partial result p
log ("Error: " & m & number)
--also reset text item delimiters in case of an error:
set AppleScript's text item delimiters to savedTextItemDelimiters
--and resignal the error: error m number n from f to t partial result p
end try
set messageSpeechText to "Message from " & realName & ", subject: " & subject of thisMessage
say messageSpeechText
end repeat
else
set speechCountText to "You have no unread messages."
say speechCountText
end if
end repeat
end tell
-- Set the timespan from midnight today to midnight tomorrow
set today to (current date)
set time of today to 0 -- midnight
set tomorrow to today + (1 * days)
tell application "iCal"
repeat with theCal in every calendar
set todaysEvents to (every event of theCal whose start date > today and start date < tomorrow)
repeat with i from 1 to number of items in todaysEvents
set theEvent to item i of todaysEvents
-- Get the readabel time
set theDate to start date of theEvent
set theTime to getReadableTime(theDate)
set calSpeechText to theTime & ", " & (summary of theEvent) & "."
say calSpeechText
end repeat
end repeat
end tell
on getReadableTime(theDate)
-- Get the "hour"
set timeStr to time string of theDate
set Pos to offset of "." in timeStr
set theHour to characters 1 thru (Pos - 1) of timeStr as string
set timeStr to characters (Pos + 1) through end of timeStr as string
-- Get the "minute"
set Pos to offset of "." in timeStr
set theMin to characters 1 thru (Pos - 1) of timeStr as string
set theTime to (theHour & ":" & theMin) as string
return theTime
end getReadableTime
Edit: LIte uppsnyggad och uppdaterad kod