Mail Scheduler - Anyone want to polish these scripts?

I’ve always wished that Mail had a feature to send a message at a specific time so I cobbled together 2 scripts to do just that using iCal. It works but I thought I’d turn it over to the forum for polishing.

Step 1 - put the following script here: /Users/user_name_here/Library/Scripts/Applications/Mail/ (I named my script “Schedule Message with iCal”)

– begin script
tell application “Mail”
set messageID to (id of message 1 of drafts mailbox) as text
end tell

– it might be nice to add some code that prevents entering a time that has already occurred. It is coded to schedule a send time “today” so adding code for more robust scheduling is also a possibility.
repeat
display dialog “What time today?” default answer “10:00 AM”
set the eventTime to the text returned of the result
if the eventTime is not “” then exit repeat
end repeat

set eventStart to date (date string of (current date) & " " & eventTime)
set eventEnd to eventStart + 15 * minutes

tell application “iCal”
set scriptCal to first calendar whose name is “Scripts” – I have a calendar for events that do nothing more than trigger scripts
set scriptPath to “/Users/user_name_here/Documents/Scripts/iCal - Send Mail Message.scpt” – locate script 2 wherever you want
set mailEvent to (make new event at end of event of scriptCal)
set summary of mailEvent to messageID
tell mailEvent
make new open file alarm at beginning of open file alarms with properties {trigger interval:0, filepath:scriptPath}
set the start date to eventStart
set the end date to eventEnd
end tell
end tell
– end script

Step 2 - put the following script here: /Users/user_name_here/Documents/Scripts/iCal - Send Mail Message.scpt (I named my script “iCal - Send Mail Message.scpt”)

– begin script
http://bbs.applescript.net/viewtopic.php?id=20756 (Thanks Stefan!)
tell (current date) to set triggerTime to it - (its seconds)
tell application “iCal”
repeat with mailEvent in (get events of calendar “Scripts” whose start date is triggerTime)
if contents of mailEvent is not missing value then
set messageID to (get summary of mailEvent) as number
end if
end repeat
end tell

tell application “Mail”
activate
tell message viewer 1
open (every message of drafts mailbox whose id is messageID)
tell application “System Events”
keystroke “d” using {command down, shift down}
delay 1
keystroke “d” using {command down, shift down}
end tell
end tell
end tell

tell application “Finder” to activate
– end script

Step 3 - Create a new mail message with to, subject, message body, etc. and “save as draft” but do not close the message window. While new draft message is still open, launch “Schedule Message with iCal” from script menu. Close draft message window. Your new message is now in the draft mailbox waiting to be sent and iCal has created an event to send the message at the time you specified.