Re: Create new task from event script?
- From: Paul Berkowitz <berkowit@xxxxxxxxxxxxxxxx>
- Date: Sat, 21 Jan 2006 14:04:46 -0800
Title: Re: Create new task from event script? On 1/18/06 7:13 AM, in article 1137597239.501059.164420@xxxxxxxxxxxxxxxxxxxxxxxxxxxx, "eric b." <eric_g_007@xxxxxxxxxxxxx> wrote:
> I like the convenience of the "Create note from message" and "Create
> task from message" scripts that come with Entourage 2004 11.2.1.
> However, I really need a "Create task from Event" script. I haven't
> found one yet (probably not looking in the right places). Does anyone
> know where I might find such a script?
Here: save the following script in Script Editor as "Create Task from Event \coT.scpt" to be able to run it on a selected event in the calendar (Entourage 2004) or one or more selected events in a Calendar View, and also run it using the shortcut control-option-T, after saving it to the Entourage Script Menu Items folder.
There are a number of options below for creating a reminder for the task: the version here makes the same reminder as the event has (if any). But normally you would not want duplicated reminders (unless you're deleting the event). So you can omit the reminder by commenting out that line by preceding it with --, as you'll see with many comment lines below. You can also choose to "uncomment" (remove the -- ) before alternate lines that set the task's reminder to the beginning of the due date (midnight), 24 hours before the exact start time of the event, or 24 hours before the due date. You can set it to any other time equally well - use (12 * hours) for example instead of (1 * days).
If you're only doing one at a time, it will open the task at the end, and you can make adjustments there.
It adds " (the location)" to the name of the task if the event has a location. You can just remove that line if you don't want it.
There's no way for AppleScript to ascertain the occurrence you've selected of a recurring event. It can only get the full recurring event - all occurrences. So it makes a recurring task (all occurrences, including past ones, incomplete) if you select a recurring event. You'll get an alert if you do. You can always cancel, duplicate the event, change the duplicate to a Once Only non-recurring event, and then select that one. (Or if you regularly want to make recurring tasks and are tired of getting the alert just remove that section of the script , from 'if' to 'end if'.)
---------------------Create Task from Event \coT.scpt -----------------------
tell application "Microsoft Entourage"
try
-- get the currently selected event (in calendar or custom view) or events (in 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
-- 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
beep 2
display dialog "You have selected at least one item in a custom view which is not a calendar event. Select only calendar events. Then try again" buttons {"Cancel"} default button 1 with icon 0
end if
--if it's a recurring event, alert the user that a recuring task will be made with all occurrences,with option to cancel to make single occurrence event first
if recurring of theEvent then
beep
display dialog "This is a recurring event whose first occurrence may be an earlier date. The script will make a recurring task on the same recurrence, with no occurrences marked as Completed. The script cannot ascertain which occurrence (date) you have selected." & return & return & "If you want to create just a single, non-recurring task for this date, Cancel, then make a duplicate event, change it to a \"once Only\" non-recurring event, save it and selec that one before running the script again." buttons {"Cancel", "Continue"}
end if
-- 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}
-- need to convert from event remind time (minutes before event as integer,to precise remind date and tim, as date obkect, 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
tell me to set theDueDate to date (date string of theStartTime)
-- 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:theDueDate, 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:theDueDate, 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
-- uncomment the next line (remove -- ) to make the task's reminder the beginning of the day (midnight) of the due date
-- if hasReminder then set remind date and time of newTask to theDueDate
-- or uncomment the next line (remove -- ) to make the task's reminder 24 hours before the event's exact start time
--if hasReminder then set remind date and time of newTask to (theStartTime - (1 * days))
-- or uncomment the next line (remove -- ) to make the task's reminder 24 hours before the task's due date (midnight)
--if hasReminder then set remind date and time of newTask to (theDueDate - (1 * days))
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
end repeat
if (count theEvents) = 1 then open newTask
end tell
------------------------------------------------------
--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>
Please "Reply To Newsgroup" to reply to this message. Emails will be ignored.
PLEASE always state which version of Microsoft Office you are using - **2004**, X or 2001. It's often impossible to answer your questions otherwise.
- References:
- Create new task from event script?
- From: eric b.
- Create new task from event script?
- Prev by Date: Re: Exporting Calendar Question
- Next by Date: Re: font size
- Previous by thread: Create new task from event script?
- Next by thread: Automatically update Entourage (2004) Inbox Cache
- Index(es):