Applescript Objective C EventKit's event start time

Using Applescript Objective C EventKit, I am unable to capture the values of an event’s start time.

For example, using EventKit I have found the following event:

EKEvent <0x3b7220>, title:Tom Jefferson, localUID:local_41BEE42F-1C26-43FD-B56D-BB6EE34DAB35, sharedUID:B70DCC06-9FC9-490A-B762-5C410841491E

Although I can see the summary of the event, which EKEvent keys as “title”, how can I capture other values of the event, such as its start time?

Download my CalendarLib EC script library from here:

https://www.macosxautomation.com/applescript/apps/Script_Libs.html

It’s code should tell you all you want to know.

Shane Stanley’s “CalendarLib EC” allows me to fetch a calendar, if I know its name. How would I be able to fetch a calendar based upon a more enduring property, such as its serverPath? As the calendar name is easily changed, I want to avoid losing track of the calendar, should a user want to change the calendar’s name.

For example, the following script fetches a calendar named “Client Scheduling” but is unable to identify the calendar should that calendar name be changed.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use script "CalendarLib EC" version "1.1.3" 
use scripting additions

set theStore to fetch store
set theCal to fetch calendar "Client Scheduling" cal type cal local event store theStore 

You can use the calendarIdentifier property, then use calendarWithIdentifier:.

Now that Applescript, via Shane Stanley’s “CalendarLib EC”, fetches a calendar called theCalendarTitle, creates a calendar event, and stores it in EventStore, my attempt has been unable to show the event using application “Calendar” without provoking an Applescript Execution Error
→ Calendar got an error: Can’t get event “0D70EDFC-CCF7-4720-B589-843873EC3674”.

use AppleScript version "2.4"
use script "CalendarLib EC" version "1.1.3" 
use scripting additions

set theStore to fetch store
set Delegate_Appointments_Calendar to fetch calendar theCalendarTitle cal type cal cloud event store theStore 

set theEvent to create event event store theStore ¬
	destination calendar Delegate_Appointments_Calendar ¬
	event summary theSummary ¬
	starting date theStartDate ¬
	ending date theEndDate ¬
	event location theEventLocation ¬
	event description theDescription ¬
	without runs all day
set EventIdentifier to event identifier for event theEvent
store event event theEvent event store theStore

tell application "Calendar"
	show event EventIdentifier
end tell

  1. How does the store’s event identifier differ from the Calendar event uid?
  2. What would be the correct method to show a Calendar event?

If you get event info for of an event, the value for event_external_ID is what Calendar.app uses for event ID. You probably then want “show event id theExternalID”.

Shane,
Even with a variable assigned to the event’s external ID, Calendar returns an error, stating that it is cannot get that event id. In the following case, I have included the values of the event’s external ID, and of Calendar’s Applescript error.

set theEvent to create event event store theStore ¬
	destination calendar Delegate_Appointments_Calendar ¬
	event summary theSummary ¬
	starting date theStartDate ¬
	ending date theEndDate ¬
	event location theEventLocation ¬
	event description theDescription ¬
	without runs all day
set EventExternalID to event_external_ID of (event info for event theEvent)
-->596586F5-0A8B-4C57-AF51-2B347697DE24

store event event theEvent event store theStore

tell application "Calendar"
	show event id EventExternalID
--> Calendar got an error: Can’t get event id "596586F5-0A8B-4C57-AF51-2B347697DE24".

end tell

It appears that either:

  1. EventKit and Calendar do not access the same database, or
  2. My Applescript syntax for accessing the event id is not fully correct
    Can you share your insights on this dilemma?

In Calendar.app, it looks like events have to be accessed via calendars. So you’ll have to refer to “event id someId of calendar…”