- Arvid
- Medlem ●
- Nacka
- 2008-07-11 10:00
Klicka här för starten på det hela
Såhär ser koden ut just nu:
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 -- 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 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
Jag har två problem just nu:
1. Jag skulle dels vilja kunna använda getReadableTime inne i event-loopen också, men det verkar inte fungera. Jag får felmeddelandet "" om jag lägger in anropet istället för koden där...
2. Som det är nu kommer kalenderinläggen i omvänd ordning (det senaste först) och det vill jag ju inte. Har försökt med följande kodsnutt, men i är tydligen inte bara en siffra utan en speciell id-kod
.... snip .... repeat with i from 1 to number of items in todaysEvents set n to (items in todaysEvents) set j to n - i + 1 set theEvent to item j of todaysEvents .... snip ....
Någon som har några förslag?
(använder för övrigt awaken för att starta upp scriptet - se inlägget som länkas ovan för en länk)