So i wrote a simple script that parse’s an e-mail’s contents into specific variables and then creates an ical event using said variables. as a plain script, with a message selected in mail.app it works flawlessly. however, when i set it to be triggered by a rule, nothing happens. first, here is the content of the email (right now, it has to be in this format):
the subject line has to correspond with an existin iCal calendar.
the body is:
OI, Financial
Mike Johnson x32338
12/27/07 1:00 PM
12/27/07 3:00 PM
50 people
This is a test event with information for an iCal Entry. Attempt for Mail Rule #2
when a message is sent with this content, the following script works when run from AS
tell application "Mail"
set allMessages to selection
-- cycle through all new messages
repeat with i from 1 to count of allMessages
set theMessage to (item i of allMessages)
set theContent to (content of theMessage) as text
set AppleScript's text item delimiters to ASCII character 10
-- parse details from e-mail for iCal
set theCalendar to subject of theMessage
set theGroup to text item 1 of theContent
set theContact to text item 2 of theContent
set theStart to text item 3 of theContent
set theEnd to text item 4 of theContent
set theAttendees to text item 5 of theContent
set theNotes to text item 6 of theContent
end repeat
end tell
set startDate to date theStart
set endDate to date theEnd
--enter iCal event
tell application "iCal"
tell calendar theCalendar
set newEvent to (make new event at end of events with properties {summary:theGroup, location:theContact, start date:startDate, end date:endDate, description:theNotes})
end tell
tell newEvent
make new attendee at beginning of attendees with properties {display name:theAttendees, participation status:unknown}
end tell
end tell
however, when i set a rule to trigger this, nothing happens. if i select the message and choose “apply rules” it works.
to further the issue, i adapted this script to what i thought was a “rule-friendly” format, as follows:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
repeat with eachMessage in theMessages
tell application "Mail"
tell eachMessage
set theMessage to (item i of allMessages)
set theContent to (content of theMessage) as text
set AppleScript's text item delimiters to ASCII character 10
-- parse details from e-mail for iCal
set theCalendar to subject of theMessage
set theGroup to text item 1 of theContent
set theContact to text item 2 of theContent
set theStart to text item 3 of theContent
set theEnd to text item 4 of theContent
set theAttendees to text item 5 of theContent
set theNotes to text item 6 of theContent
end tell
set startDate to date theStart
set endDate to date theEnd
--enter iCal event
tell application "iCal"
tell calendar theCalendar
set newEvent to (make new event at end of events with properties {summary:theGroup, location:theContact, start date:startDate, end date:endDate, description:theNotes})
end tell
tell newEvent
make new attendee at beginning of attendees with properties {display name:theAttendees}
end tell
end tell
end tell
end repeat
end perform mail action with messages
end using terms from
This does not work even when the rule should have been triggered (scanning “from” address or subject content) nor by choosing “apply rules.”
Any help would be greatly appreciated.
Mike
Model: Mac Pro, Octo
AppleScript: 1.10.7
Browser: Firefox 2.0.0.11
Operating System: Mac OS X (10.4)