In Microsoft Entourage 2004, tasks and notes are local, not on Microsoft Exchange servers. You make a new task in the same way that you make a new message, contact, and event. For more information about making new items, see Create or open a contact.
This script includes making a new task, and discusses the main difference between task and event, namely the different types of reminders they have.
The Entourage menu comes with three scripts: Create Event from Message, Create Note from Message, and Create Task from Message. Often, it would be handy to be able to create a task from an event, especially if someone sends you an .ics file from another application that can be imported into Entourage but appears as a calendar event with a fixed time (probably midnight!), when you'd actually prefer to have it as a task.
This script will do it:
tell application "Microsoft Entourage"
try
(*get the currently selected event(s)
(in calendar or custom view) *)
set theEvents to (get selection)
if theEvents = {} or class of (item 1 of theEvents) ¬
is not event then error number -128
on error
(*if there are no events selected, or the first item selected
is not a calendar event, warn the user and then quit*)
beep 2
display dialog "First select an event in the calendar or " & ¬
"a custom view. Then try again" buttons {"Cancel"} ¬
default button 1 with icon 0
end try
repeat with theEvent in theEvents
repeat 1 times
(* if any subsequent item (in a custom view) selected
is not a calendar event, warn the user and then quit *)
if class of theEvent is not event then exit repeat
(* get the information from the event,
and store it in variables*)
set {theTitle, theLocation, theStartTime, hasReminder, ¬
theReminder, ifRecurring, theRecurrence, ¬
theCategories, theProjects, theNotes, theLinks} ¬
to theEvent's {subject, location, start time, ¬
has reminder, remind time, recurring, ¬
recurrence, category, project list, content, ¬
links}
(*if it's a recurring event, find when the next
occurrence is due and make that the start time *)
if recurring of theEvent then
set now to (current date)
copy now to checkDate -- copy, not set
set year of checkDate to ((year of checkDate) + 1)
-- a year from now
set allOccurrences to calculate recurring dates for ¬
theEvent from theStartTime to checkDate
set nextOccurrence to missing value -- initialize
repeat with i from 1 to (count allOccurrences)
set thisOccurrence to item i ¬
of my allOccurrences
if thisOccurrence > now then
-- first occurrence after now
set nextOccurrence to thisOccurrence
exit repeat
end if
end repeat
if nextOccurrence = missing value then exit repeat
-- skip, since no longer occurring
set theStartTime to nextOccurrence
-- forget occurrences in the past
end if
(*need to convert from event remind time (minutes before
event as integer) to precise remind date and time,
as date object, for task) *)
if hasReminder then set theReminder to ¬
(theStartTime - (theReminder * 60))
(*set the task's due date to just the date
(i.e., midnight) of the event's start time*)
set time of theStartTime to 0
(* remove or comment out (--) the next line if you
don't want the location added to the title *)
if theLocation ≠ "" then set theTitle to ¬
(theTitle & "(" & theLocation & ")")
(*if it's not a recurring task, must omit 'recurring'
from properties*)
if ifRecurring then
set newTask to make new task with properties {name:¬
theTitle, due date:theStartTime, ¬
completed:false, recurring: true, ¬
recurrence:theRecurrence, ¬
category: theCategories, ¬
project list:theProjects, content:theNotes}
else
set newTask to make new task with properties {name:¬
theTitle, due date:theStartTime, ¬
completed:false, category: theCategories, ¬
project list:theProjects, content:theNotes}
end if
(*sets the task's reminder to the same as the original
event's reminder: or comment out the line with --
to not duplicate the reminder *)
if hasReminder then set remind date and time ¬
of newTask to theReminder
link newTask to theEvent
repeat with i from 1 to (count theLinks)
set theLink to item i of theLinks
try
link theLink to newTask
end try
end repeat
(* optionally delete the event by uncommenting
(remove -- from next line)
*)
--delete theEvent
end repeat -- 1 times
end repeat
if (count theEvents) = 1 then open newTask
end tellRegarding the section in the middle concerning recurring events and tasks: you might have selected an event in the current week or month of the calendar that is a recurring event whose first occurrence may have been weeks or years ago. You do not want a recurring task with a due date of two years or two weeks ago, complete with a reminder for past overdue occurrences, but rather one whose first occurrence is the next occurrence. This is particularly so because the format for recurring tasks is such that there is simply one incomplete task at a time. The next occurrence is not created by Entourage until you complete the current one, so you would see only the old due date of the original occurrence's start time.
The script uses the calculate recurring dates for command that was introduced in Entourage 2004, which needs from and to framing dates. You need to start with the original start time and stop a year from now, which should include the next occurrence even if it's a yearly event such as a birthday. You run through all of the dates until you hit the first one in the future (> now) and that's your next occurrence. You make that date the new
theStartDate, which will be set as the due date for the task.
The remind time property of the event object, like the settings in the UI, is an integer representing the number of minutes before the start time of the event. But the remind date and time property of the task object is a date object representing a precise date and time (in the UI arrived using a mini-calendar and a clock), no doubt because the due date is just a date without a time component.
In any case, you have to do the calculation of subtracting 60 times the event's reminder (to convert the minutes into seconds) from the event's start time to get the date-time form for the task's reminder. You also use another variable to set the time of the event's start time to 0 (that is, midnight) to get the right form for the due date of the task.
There is a line that adds any Location field information from the event to the task's title in parentheses. If you don't want this, remove the line.
Finally, the script needs to check again whether the event was a recurring task. If not, then you must completely omit any mention of the recurring and recurrence properties (even though the recurring property is false) when making the new task, or it will be turned into a recurring task with the default recurrence pattern of every day. So you need an
if
block to cover the two possibilities.
There is an option line if you now want to delete the original event once the task is made. If so, uncomment the delete line (remove the double-dash,
--, before) . If you selected only one event (count theEvents = 1), the script opens it for you to make any adjustments.


