Re: iCal organization with dates & events & lists....
Re: iCal organization with dates & events & lists....
- Subject: Re: iCal organization with dates & events & lists....
- From: Adam Wuellner <email@hidden>
- Date: Mon, 21 Mar 2005 13:49:43 -0600
On Thu, 17 Mar 2005 01:21:05 -0800 (PST), Patrick Collins
<email@hidden> wrote:
> the code is:
> [...]
Bearing in mind that a complete and generalized solution will require that the
recurrence of events be properly accounted for, as pointed out by
Peter and Paul,
this is my last submission on the topic. It deals with getting the event
properties from the user's list choice.
The problem is this: you have a list of items such as event references, and a
list of descriptions for those items, and you want to retrieve the event
reference that relates to the string chosen by the user from the list of
descriptions.
A solution is this: embed the item index in the description string. Then, parse
the index number from the text returned from the (choose from list ...) call,
and use it to directly grab the corresponding item from the associated list.
This does add a little 'noise' to the UI, but it avoids the need to
loop through
the lists looking for a match based on the chosen string.
Example:
-- event_list is a list of lists.
-- each sublist is the uid, start date, and summary of an event in the calendar
tell application "iCal"
set event_list to {}
repeat with an_event in events of calendar 1
tell contents of an_event
set event_list to event_list & {{uid, start date, summary}}
end tell
end repeat
end tell
-- event_list's lists are sorted by item 2, the start date
set event_list to sort_lists of event_list by 2
-- choice_list is a list of strings to show the user
-- e.g. {"1) 01/01/01 - Some meeting", "2) 01/02/01 - Another meeting", ...}
set choice_list to {}
repeat with i from 1 to count event_list
set choice_list to choice_list & {"" & i & ") " & ¬
short date string of item 2 of item i of event_list & " - " & ¬
item 3 of item i of event_list}
end repeat
-- LOOK, MOM, NO (more) REPEATS!
-- chosen_index is the number from the chosen string
choose from list choice_list
set chosen_index to first word of first item of result
-- uid_ is the uid of the event that the user chose
set uid_ to first item of item chosen_index of event_list
-- script returns the properties of the chosen event
tell application "iCal"
tell calendar 1
get properties of first event whose uid is uid_
end tell
end tell
-- list-sorting handler, probably could be improved
-- sort a list of lists by an item in the sublist
on sort_lists of main_list by item_index
local sorted_list, main_list, i, j, item_index, stored
set sorted_list to {contents of item 1 of main_list}
set main_list to rest of main_list
repeat with i from 1 to count main_list
set stored to false
repeat with j from 1 to count sorted_list
if (contents of item item_index of item i of main_list) < ¬
(contents of item item_index of item j of sorted_list) then
if (j > 1) then
set sorted_list to (items 1 through (j - 1) of sorted_list) & ¬
{contents of item i of main_list} & ¬
(items j through (count of sorted_list) of sorted_list)
else
set beginning of sorted_list to (contents of item i of main_list)
end if
set stored to true
exit repeat
end if
end repeat
if stored is false then set sorted_list to sorted_list & ¬
{contents of item i of main_list}
end repeat
return sorted_list
end sort_lists
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden