Hey all,
I’m working on a script that needs to review all of my recurring calendar entries and it stores some information in a file. I’m trying to run the script on an exchange account and I do not have access to the apis and so it needs to be done locally using AppleScript.
Not a problem, I’ve got a script that works. However, the exchange account in question has 15-years worth of calendar entries in it and it runs hideously slow regardless of how far back I set the script to filter. I’ve included a cut-down version of the script below.
The culprit line will inevitably be …
set calendarEvents to every calendar event of theCal whose is recurring is true and modification date is greater than or equal to startDate
Is there a better way to structure and possibly nest this query to make it more performant?
Thanks in advance!
tell application "Microsoft Outlook"
set theCal to "104"
set theCal to calendar id theCal
set startDate to (current date) - 20 * days
set calendarEvents to every calendar event of theCal whose is recurring is true and modification date is greater than or equal to startDate
set eventList to {}
--set eventListString to ""
repeat with calendarEvent in calendarEvents
set eventProperties to properties of calendarEvent
set recProperties to recurrence of eventProperties
--copy {id of calendarEvent, icalendar data of eventProperties} to end of eventList
copy {id of calendarEvent, subject of eventProperties, modification date of eventProperties} to end of eventList
--set eventListString to eventListString & icalendar data of eventProperties
end repeat
return eventList
--return eventListString
end tell
Try to set the variable calendarEvents not to value (that is, to filtered events) but to a reference to filtered events. Logically, then you can get eventList without repeat loop. The Outlook.app is not installed on my Mac, so I can’t test following:
set theCal to "104"
set startDate to (current date) - 20 * days
tell application "Microsoft Outlook"
set theCal to calendar id theCal
set calendarEvents to a reference to calendar events of theCal whose is recurring is true and modification date is greater than or equal to startDate
return {id , subject, modification date} of calendarEvents
end tell
Here is a faster version (I think).
I removed anything that didn’t need to be in the “Tell” block outside.
set startDate to (current date) - 20 * days
tell application "Microsoft Outlook"
set theCal to "104"
set theCal to calendar id theCal
set calendarEvents to {id, subject, modification date} of (every calendar event of theCal whose is recurring is true and modification date is greater than or equal to startDate)
end tell
set eventList to {}
repeat with i from 1 to count item 1 of calendarEvents
copy {item i of item 1 of calendarEvents, item i of item 2 of calendarEvents, item i of item 3 of calendarEvents} to end of eventList
end repeat
return eventList
Let me know if it is faster and by how much?
BTW, how many calendar events are there in total? roughly
I’m using Outlook installed on my Mac to use a corporate M365 account. I want to try to use this script to get a list of events on my calendar. Any idea how I would determine what the calendar number is?
Searching Google, I’ve seen it mentioned to get that number, in my Outlook app, I would go to the calendar section. Find the calendar I want, in this case, my default calendar for my work account, and look at properties for that calendar. All I see there is a ‘general’ and ‘permissions’ tab. There is no calendar id or number anywhere there.
Thanks for any help.
try this. It will find the calendar that has an Exchange ID
tell application "Microsoft Outlook"
set myCals to calendars
repeat with aCal in myCals
if exchange id of aCal ≠ missing value then
set calID to id of aCal
exit repeat
end if
end repeat
set theCal to calendar id calID
end tell
here is a shorter version
tell application "Microsoft Outlook"
set myAccnt to exchange accounts
if (count of myAccnt) > 0 then set myAccnt to item 1 of myAccnt
set myCal to default calendar of myAccnt
end tell