Aimless noise and insights into my little world

Friday, October 12, 2007

Applescript to make an iCal event from an email

So after much gnashing of teeth and swearing about Applescript I got my little app to work. I have an Act-on key binding which triggers a script. The script takes the email and dumps it into iCal, for further correction (e.g. setting date/time of the event). If I was feeling brave/stupid I'd get the script to parse out the date, but I really don't want to do that! The script was based on a mail to todo item script I found.

using terms from application "Mail"
on perform mail action with messages selectedMessages
try
set theCalendar to "WorkEvents"
repeat with mail in selectedMessages

set theSummary to the subject of the mail
set theDescription to the content of the mail
set theDate to the date received of the mail

tell application "iCal"
make new event at the end of events of (every calendar whose
title = theCalendar) with properties {summary:theSummary,
description:theDescription, start date:theDate}
end tell
set read status of the mail to true
delete the mail
end repeat
on error errMsg number errorNumber
display dialog ("An error occurred: " & errorNumber as string)
end try
end perform mail action with messages

end using terms from


The following script does similar work, but creates a todo item instead of a new event. It also doesn't delete the original mail.


using terms from application "Mail"
on perform mail action with messages selectedMessages
try
set theCalendar to "WorkEvents"
--say theCalendar
repeat with mail in selectedMessages

set theSummary to the subject of the mail
set theDescription to the content of the mail

tell application "iCal"
--set theCalendar to choose from list every calendar with
prompt "Choose name or cancel"
make new todo at the end of todos of (every calendar whose
title = theCalendar) with properties {summary:theSummary,
description:theDescription}
end tell
set read status of the mail to true
--delete the mail
end repeat
on error errMsg number errorNumber
display dialog ("An error occurred: " & errorNumber as string)
end try
end perform mail action with messages

end using terms from

No comments: