Mail script to ical date problem...

Hi,

My work uses a calendar system that I don’t have at home, and I’d like my work appts to go into my ical calendar, so I’ve written a script to fire when a calendar entry is forwarded from my work email.

I’m 99% there, but I’ve got a strange problem with setting an iCal date, and I’ve tracked it down to the following simplified example:

– START OF SCRIPT EXAMPLE
– this date string is actually parsed from the body of the email
– I’ve just hard coded it here for simplicity
set DateString to “09/02/2004 9:00:00 AM”

using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
tell application “Mail”
repeat with eachMessage in theMessages
set myDate to date DateString
display dialog date string of myDate
end repeat
end tell
end perform mail action with messages
end using terms from

– END OF SCRIPT EXAMPLE…

When this script is triggered from Mail, it fails right at the “set myDate to date DateString”
Is it because of the “Using terms from…”?
Any ideas?
Thanks!
George

Hi,

It’s probably because ‘date’ is a keyword in Mail. Try coercing the date string to ‘date’ outside of that whole Mail block.

gl,

Hi,

I tried that and it seems that only the code within the “using/end using” block gets executed when the mail action script is run!

Any way to override Mail’s “date” and use the regular one?

I’m stumped!
George

Hi George,

Try leaving the statement where it was and target the script with ‘me’ or ‘my’. Something like this:

property DateString : “09/02/2004 9:00:00 AM”

tell application “Mail”
set the_date to (date DateString) of me
end tell

gl,

Hi,

Thanks for the suggestion, but it doesn’t work :frowning:

To repro this problem, you need to paste the original code into a new script, open Mail.app and create a new rule that will trigger the script. Select an email tht will trigger the rule. Everything works fine, except for the date…

Still stumped! :slight_smile:

George

Hi,

Here’s your modified script using ‘my’

– START OF SCRIPT EXAMPLE
– this date string is actually parsed from the body of the email
– I’ve just hard coded it here for simplicity
set DateString to “09/02/2004 9:00:00 AM”

using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
tell application “Mail”
repeat with eachMessage in theMessages
set myDate to (my date DateString)
display dialog (my date string of myDate)
end repeat
end tell
end perform mail action with messages
end using terms from

– END OF SCRIPT EXAMPLE…

Does this work or did the error jump to a different line?

gl,

forgot to change your date string to a property

– START OF SCRIPT EXAMPLE
– this date string is actually parsed from the body of the email
– I’ve just hard coded it here for simplicity
property DateString: “09/02/2004 9:00:00 AM”

using terms from application “Mail”
on perform mail action with messages theMessages for rule theRule
tell application “Mail”
repeat with eachMessage in theMessages
set myDate to (my date DateString)
display dialog (my date string of myDate)
end repeat
end tell
end perform mail action with messages
end using terms from

– END OF SCRIPT EXAMPLE…

Hi,

It doesn’t work, it fails at the “set myDate to (my date DateString)” line. It’s got to be a conflict with the mail terms. Wonder if there’s a way to switch back within the using/end using block…
Thanks so much for looking at this…
George

Hi George,

I think I got a workaround. I’m using Mail 1.2.5, but was getting the same problem coercing string to ‘date’ when the script is called by a Mail rule. I tried coercing string to date first, by calling another handler. That didn’t work. Then I thought that calling another script might work. First, I tried using a script object instead and that worked.

property DateString : “09/02/2004 9:00:00 AM”

script TestScript
on GetDate(date_string)
return (date date_string)
end GetDate
return
end script

– info is a record of 2 fields {|SelectedMessages|:list of references,|Rule|:reference}
on perform_mail_action(info)
set message_list to |SelectedMessages| of info
set the_rule to |Rule| of info – not used in this script
set first_message to item 1 of message_list
tell application “Mail”
set the_subject to subject of first_message
end tell
set my_date to GetDate(DateString) of TestScript
display dialog (date string of my_date)
display dialog the_subject
return
end perform_mail_action

The syntax is different in this version but two main points of this workaround is to coerce the string to date within a script object and I forgot the other one :-). I’m still a little dizzy from last night.

gl,

Hi George,

Here’s another thing that might work. Jon often writes that ‘get’ might work. For instance:

set myDate to (get my date DateString)

or

set myDate to (get date DateString)

gl,