Hello Again,
I posted this project a week or so ago and no one responded. Hopefully this time you all will be more interested becasue I am SO CLOSE to finishing this script (and even closer to giving up altogether).
my overal goal is to have a free .Mac account equivilent: a platform independat ability to add events, contacts, and bookmarks and also to view them on the internet. I am doing well on the other parts but this little scrpt is killing me.
So here it is. I am trying to make it so that I send an email to myself with subject line “add event” and this tirggers a rule which will read the email and use the contents of the body to set the date, content, subject, etc of a new iCal event.
All of this is working WONDERFULLY except one little detail: dates. I can’t figure out how to get the content of the email formated into a date. Below is the script with it set to add the event to calendar “Work”.
It is canabalized from “Mail2iCal1.1.4.scpt” that I found somewhere.
Anyway please please help me figure this out becuase i have tried everything and i ust cant get the stupid date formating to work.
property pCalName : ""
property pDontAsk : false
on perform_mail_action(info)
set mailCal to my checkForDefault()
set allMessages to |SelectedMessages| of info
my generateItems(allMessages, mailCal)
end perform_mail_action
on run
tell application "Mail"
set mailCal to my checkForDefault()
set allMessages to selected messages of message viewer 1
my generateItems(allMessages, mailCal)
end tell
end run
on getIndex(theItem, theList)
repeat with i from 1 to count of theList
if theItem is item i of theList then
return i
end if
end repeat
return -1
end getIndex
on checkForDefault()
tell application "iCal"
set allCals to title of calendars
set pCalName to "Work"
set calIndex to (my getIndex(pCalName, allCals))
set mailCal to calendar calIndex
end tell
return mailCal
end checkForDefault
on generateItems(allMessages, mailCal)
tell application "Mail"
repeat with curMessage in allMessages
set theSender to sender of curMessage
set theSubject to subject of curMessage
set mailContents to content of curMessage
set {test1, test2} to paragraphs of mailContents
set theBody to test2
--here is the trouble spot. I just have it set to current date right now so you
--can see that this script does work. just how to get a paragraph from the
--contents to be turned into a date?
set theDate to current date
tell application "iCal"
set newEvent to (make new event at the end of events in mailCal)
tell newEvent
set start date to theDate
set end date to ((theDate + minutes) as date)
set summary to (theSender & ", " & theSubject)
set description to theBody
end tell
end tell
end repeat
end tell
end generateItems