Hi all!
I am using “CalendarLib EC” to extract future events (for the next 7 days) from different calendars (of iCal).
At the end I get a list of events which are not sorted as I want.
Is there any way to sort events by " starting date"?
The script I am developing is:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use script "CalendarLib EC" version "1.1.3" -- put this at the top of your scripts
set choosedCals to {"Home", "Personal", "Not_Sync", "Urgent_Lux", "Work"}
set d1 to current date
set d2 to d1 + 7 * days
set theStore to fetch store
set AllEvents to {}
set AllEventsFlat to {}
set AllCals to {}
set MaxEvent to 8
repeat with y in choosedCals
set end of AllCals to fetch calendar y cal type cal cloud event store theStore -- change to suit
end repeat
repeat with z in AllCals
set myEvents to fetch events starting date d1 ending date d2 searching cals {z} event store theStore
if (count of myEvents's items) > 0 then
set end of AllEvents to fetch events starting date d1 ending date d2 searching cals {z} event store theStore
set AllEventsFlat to (AllEventsFlat & (fetch events starting date d1 ending date d2 searching cals {z} event store theStore))
end if
end repeat
# let's remove all day-long events
set AllEventsFlat to filter events event list AllEventsFlat without runs all day
# let's sort all events based on starting date
set MySortingList to {}
repeat with anEvent in AllEventsFlat
anEvent
set InfoEvent to (event info for event anEvent)
set end of MySortingList to {start_date:(event_start_date of InfoEvent), eventID:(event_external_ID of InfoEvent)}
end repeat
As you will see at the end of the script, I was creating a list for each event by extracting “event_start_date” and “event_external_ID”.
My thinking was: if I can sort this list based on the date, then I will also sort the event_external_ID.
I am not sure I have explained myself.
Thanks.
L.