Re: Reading Calendar events - need comments/suggestions
Re: Reading Calendar events - need comments/suggestions
- Subject: Re: Reading Calendar events - need comments/suggestions
- From: Shane Stanley <email@hidden>
- Date: Sat, 17 Mar 2018 10:27:00 +1100
On 17 Mar 2018, at 8:37 am, Jan Erik Moström <email@hidden> wrote:
>
> However, there are a couple of problems with it:
>
> + It's slow ... it takes about 20 seconds to execute the script, according to
> Script Debugger most of the time is spent sending events (if I understand
> things correctly)
Calendar is unbearably slow. It's also buggy in that when you filter by start
and end date, it only considers the initial dates for recurring events. Try to
avoid it.
If you go here
<https://www.macosxautomation.com/applescript/apps/Script_Libs.html> you can
download either CalendarLib EC (requires macOS 10.11 or later) or CalendarLib.
They will speed up your script significantly.
>
> + The second is the time stamps, is there some way to get "HH:MM" instead of
> "HH:MM:SS" or do I need to do that formatting myself.
You have to do that yourself.
> + What is the best way to get the result sorted?
CalendarLib returns results sorted by start date.
>
> + Also, please tell me how this script can be improved.
You can use Calendar to get the names of calendars, and then use on the
libraries to do the rest. Here's an example using CalendarLib EC:
use script "CalendarLib EC" version "1.1.3" -- put this at the top of your
scripts
use scripting additions
set theStartDate to (current date)
set hours of theStartDate to 0
set minutes of theStartDate to 0
set seconds of theStartDate to 0
set theEndDate to theStartDate + (1 * days) - 1
set skipList to {"X", "Y", "Z"}
tell application id "com.apple.iCal" -- Calendar
set calNames to name of calendars
end tell
set newCalNames to {}
repeat with aName in calNames
if aName is not in skipList then
set end of newCalNames to contents of aName
end if
end repeat
set theStore to fetch store -- get the event store, which you need below
set theCalendars to fetch calendars newCalNames event store theStore -- get the
chosen calendars
set theEvents to fetch events starting date theStartDate ending date theEndDate
searching cals theCalendars event store theStore -- get the events
--return event info for event (item 1 of theEvents)
set listEvents to ""
repeat with anEvent in theEvents
set theInfo to event info for event anEvent -- 'event info for' returns
a record of most of an event's properties
-- eg: {event_external_ID:"128", event_location:missing value,
event_end_date:date "Tuesday, 13 March 2018 at 12:00:00 am",
event_start_date:date "Monday, 12 March 2018 at 12:00:00 am",
event_time_zone:missing value, event_status:"none", event_description:missing
value, event_url:missing value, event_organizer:missing value,
calendar_type:"cloud", all_day:true, event_creation_date:date "Tuesday, 7
October 2014 at 12:21:51 pm", event_original_date:missing value,
event_attendees:{}, event_is_recurring:false, event_summary:"Eight Hours Day
(TAS)", calendar_name:"Australian Holidays"}
set listEvents to listEvents & (text -2 thru -1 of ("00" & (hours of
event_start_date of theInfo))) & ":" & (text -2 thru -1 of ("00" & (minutes of
event_start_date of theInfo))) & " - " & (text -2 thru -1 of ("00" & (hours of
event_end_date of theInfo))) & ":" & (text -2 thru -1 of ("00" & (minutes of
event_end_date of theInfo))) & space & event_summary of theInfo & return
end repeat
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden