Description: Adds To Do items to the specified calendar. This is
intended as a workaround until someone fixes the iCal plugin to work
with OS X 10.5.
Where to save: ~/Library/Application Support/Quicksilver/Actions. The
saved script must be named "Create iCal To-Do in <Calendar
Name>.scpt", where <Calendar Name> is the name of the calendar to
which the To Do items are to be added.
Usage:
The following script makes to do items from text data in the form "get
milk due: Wed 4:15 pm priority: low"
Setting the due date is optional. The due date can take various
forms, including "May 20", "May 20, 2008", "20 may 08", "5/20/08" or
using the full or abbreviated name of the weekday. Weekday names are
always understood to indicate the first one with that name after
today. So if one were to enter the text above on a Wednesday, the
action would make the to do item due on the following Wednesday. If
it were entered on a Tuesday, the to do item would be due the next
day.
Setting the time due is a further option with the due date. 1pm,
10:30am, and 4:15 pm are all valid formats for the time. Times must
include "am" or "pm" or the action will fail. If a time due is not
specified, the event will be due at 12:00 AM on the date due. If a
time due is given, but no date due is given, it is assumed that the to
do item is due today at that time.
Setting the priority is also optional. Priority may be "high",
"medium" or "med", or "low". If no priority is specified, the to do
will be given a priority of none.
Code:
using terms from application "Quicksilver"
on process text inputText
set theCalendar to name of (info for (path to me))
set theCalendar to findReplace(".scpt", "", theCalendar)
set theCalendar to findReplace("Create iCal To-Do in ", "",
theCalendar)
set dueDate to ""
set pty to ""
set inputText to findReplace(" due:", "||due|", inputText)
set inputText to findReplace(" due ", "||due|", inputText)
set inputText to findReplace(" priority:", "||priority|", inputText)
set inputText to findReplace(" priority ", "||priority|", inputText)
set inputText to delimitText("||", inputText)
repeat with i from 1 to number of items in inputText
if item i of inputText contains "due|" then
set dueDate to item i of inputText
set item i of inputText to ""
else if item i of inputText contains "priority|" then
set pty to item i of inputText
set item i of inputText to ""
end if
end repeat
set inputText to (inputText as text)
try
set dueDate to findReplace("due|", "", dueDate)
set dueDate to getdate(dueDate)
end try
try
set pty to findReplace("priority|", "", pty)
end try
tell application "iCal"
ignoring case, hyphens, punctuation and white space
if pty is "high" then
set pty to high priority
else if pty is "medium" or "med" then
set pty to medium priority
else if pty is "low" then
set pty to low priority
else
set pty to no priority
end if
end ignoring
if dueDate is not "" then
set propertyList to {summary:inputText, due date:dueDate,
priority:pty}
else
set propertyList to {summary:inputText, priority:pty}
end if
make new todo with properties propertyList at end of todos in
calendar theCalendar
end tell
end process text
end using terms from
----------
on findReplace(findText, replaceText, sourceText)
set ASTID to ""
set AppleScript's text item delimiters to findText
set sourceText to text items of sourceText
set AppleScript's text item delimiters to replaceText
set sourceText to "" & sourceText
set AppleScript's text item delimiters to ASTID
return sourceText
end findReplace
on delimitText(delim, sourceText)
set ASTID to ""
set AppleScript's text item delimiters to delim
set sourceText to text items of sourceText
set AppleScript's text item delimiters to ASTID
return sourceText
end delimitText
on getdate(thedatetext)
if "am" is in thedatetext or "pm" is in thedatetext then
set thedatetext to findReplace(" am", "am", thedatetext)
set thedatetext to findReplace(" pm", "pm", thedatetext)
set thedatetext to delimitText(" ", thedatetext)
set thetimetext to last item of thedatetext
set thetimetext to time string of (date thetimetext)
set the last item of the thedatetext to ""
set thedatetext to thedatetext as text
end if
set thedaysoftheweek to {"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"}
ignoring case, punctuation and white space
if thedatetext is in (thedaysoftheweek as text) then
repeat with i from 1 to 7
if thedatetext is in item i of thedaysoftheweek then
set thedatetext to item i of thedaysoftheweek
exit repeat
end if
end repeat
set theDate to
DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date,
thedatetext, 1)
else
set theDate to (date thedatetext)
end if
set thedatetext to date string of theDate & " " & thetimetext
set theDate to (date thedatetext)
end ignoring
return theDate
end getdate
on DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(d, w, i) --
returns a date
-- Keep an note of whether the instance value *starts* as zero
set instanceIsZero to (i is 0)
-- Increment negative instances to compensate for the following
subtraction loop
if i < 0 and d's weekday is not w then set i to i + 1
-- Subtract a day at a time until the required weekday is reached
repeat until d's weekday as text is w
set d to d - days
-- Increment an original zero instance to 1 if subtracting from
Sunday into Saturday
if instanceIsZero and d's weekday is Saturday then set i to 1
end repeat
-- Add (adjusted instance) * weeks to the date just obtained and zero
the time
d + i * weeks - (d's time)
end DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate