So I decided to fiddle with Applescript a bit to see if I could come
up with a replacement for the Create iCal To-Do action.

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.

You will need to save a copy of this script for each calendar you want
to add to do items to.  For example, to make to do items in a calendar
called "Work", save a copy of this script in the QS actions folder as
"Create iCal To-Do in Work.scpt"  It is important to follow this name
convention precisely, or the script will not work.

Here is the script:

using terms from application "Quicksilver"
        on process text inputText
                --set inputText to "eat more cheese due wed 4:15 pm priority: 
high"
                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



On May 4, 7:53 pm, Sesquipedalian <[EMAIL PROTECTED]> wrote:
> Was the Birthday calendar the first one created?  Because mine always
> get added to the first one I made (the ability to select the proper
> calendar in the third pane is currently broken).  Try disabling the
> Birthday calendar, restarting iCal, and then re-enabling the Birthday
> calendar.
>
> On May 4, 12:33 pm, Bwest <[EMAIL PROTECTED]> wrote:
>
> > Thanks for the attempt Sesquipedalian. Unfortunately it doesn't seem
> > to matter which calendar is selected in iCal. I think I am going to
> > have to wait for the plug in to be updated for Leopard.
>
> > On May 1, 9:57 pm, Sesquipedalian <[EMAIL PROTECTED]> wrote:
>
> > > My guess is that you have the birthday calendar selected in iCal, and
> > > the Create iCal To-Do action is therefore attaching your to do items
> > > to it.  Try selecting another calendar in iCal and then using the QS
> > > action.
>
> > > As fro removing the items you have made, try this:
>
> > > Make sure iCal is not running.
> > > In Finder, press ⌘F to open a new search window.
> > > In the Search criteria, select Other from the first drop list.  When
> > > the dialog box opens, choose "System files" and then select include in
> > > the second drop list.
> > > Type the name of the to do item (e.g. "get milk") into the search
> > > box.  This should bring up the to do item in the results list.
> > > Press ⌘⌫ to trash the item.  You may need to give an admin password.
> > > For good measure, you might also trash ~/Library/Calendars/Calendar
> > > Cache before restarting iCal.
>
> > > Hopefully that will do the job, but I promise you nothing.
>
> > > On May 1, 3:33 pm, Bwest <[EMAIL PROTECTED]> wrote:
>
> > > > I recently discovered the iCal add To Do function which is great.
> > > > Unfortunately, the to do's are being created under my birthday
> > > > subscription calendar and I cannot modify them after creation. Does
> > > > anyone know how to get QS to create the to do's in my personal
> > > > calendar?
>
> > > > I did see that iCal was rewritten in Leopard and the plug in may not
> > > > be sufficiently rewritten here:
>
> > > >http://groups.google.com/group/blacktree-quicksilver/browse_thread/th...
>
> > > > Addtionally, anyone now know how to delete the un-modifiable birthday
> > > > calendar to do's?
>
> > > > Thanks for your help....

Reply via email to