Hello there,
I’m trying to write a suite of scripts to create a ‘Tickler File’ in Mail, that will let me defer a selected message until a certain date. Using Mail Act On, I’ve set up scripts to put mails in Month/Day folders at some relative time in the future (1 day, 1 week, 2 weeks, 4 weeks) and these work fine, creating the necessary folders and moving the mail. The script to fetch the messages also works well and deletes empty folders, etc. So, most of the code has been tested in other forms.
I’m now trying to write a script to file mails for a specific date in the future, taking the date from two dialog boxes. As soon as the first box appears, if it appears at all, Mail crashes. On a very rare occasion, the box will appear OK, but then I can’t write into it, just click OK.
If anyone could help me figure this one out, they would have my eternal gratitude.
Thanks,
Ross
(sorry if the code is a little messy, I’m new to this and I’ve been hacking and slashing in frustration!)
-- The tickler folder
property tickler : "@TICKLER"
property FOLDERS_MONTHS : {"01.Jan", "02.Feb", "03.Mar", "04.Apr", "05.May", "06.Jun", "07.Jul", "08.Aug", "09.Sep", "10.Oct", "11.Nov", "12.Dec"}
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
-- Preparatory work
set month_ok to false
set day_ok to false
if ((year of (current date)) mod 4) is equal to 0 then
set days_in_feb to 29
else
set days_in_feb to 28
end if
set DAYS_EACH_MONTH to {31, days_in_feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
set this_month to ((month of (current date)) as integer)
set this_day to day of (current date) as integer
display dialog "Which Month?" default answer this_month buttons ["OK"] default button "OK"
if (text returned of result) is not "" then
set chosen_month to text returned of result
try
set days_this_month to item (chosen_month as integer) of DAYS_EACH_MONTH
set month_ok to true
on error
display dialog "That doesn't look like a month to me. I should be a number from 1 to 12."
end try
else
display dialog "You didn't enter a month."
end if
if month_ok then
display dialog "Which Date (1-" & days_this_month & ")?" default answer this_day buttons ["OK"] default button "OK"
try
set target_day to ((text returned of result) as integer)
set day_ok to true
on error
display dialog "That doesn't look like a date to me. I should be a number from 1 to" & days_this_month & "."
end try
end if
if day_ok then
tell application "Mail"
set target_month to item (chosen_month as integer) of FOLDERS_MONTHS
set destination_mailbox to tickler & "/" & target_month & "/" & target_day
-- Check if the month folder exists. If not, create it.
try
set mbox to mailbox named target_month
on error
make new mailbox with properties {name:(tickler & "/" & target_month)}
end try
-- Check if the day folder exists. If not, create it.
try
set mbox to mailbox named destination_mailbox
on error
make new mailbox with properties {name:(tickler & "/" & target_month & "/" & target_day)}
end try
-- Put the items in the destination folder.
repeat with eachMessage in theMessages
move eachMessage to (mailbox named destination_mailbox)
end repeat
end tell
end if
end perform mail action with messages
end using terms from
Model: MacBook
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)