Thursday, August 16, 2018

#1 2018-06-14 01:44:31 am

akim
Member
Registered: 2010-04-04
Posts: 77

loading or refreshing calendars to server

What is the EventKit method of loading calendars to synchronize calendar events on a local unit to a server? In applescript,

Applescript:

tell application "Calendar" to reload calendars

appears to refresh the local calendar or synchronize the local calendar with a server calendar.
Although I assumed that the EventKit equivalent would be to load the Event Calendars, I cannot find such EventKit function.I found an Eventkit refreshSourcesIfNecessary function, but my applescript implementation failed.

Applescript:

use framework "Foundation"
use framework "EventKit"

   # create event storage or database
   set theEKEventStore to current application's EKEventStore's alloc()'s init()
   
   # request access for theEKEventStore to assemble a database of Calendars
   theEKEventStore's requestAccessToEntityType:0 completion:(missing value)
   
   # my failed attempt to refresh sources of events to sync events with server
   theEKEventStore's refreshSourcesIfNecessary()

Perplexed.
Please let me know of any EventKit solution for event synchronization that has worked for you.

Offline

 

#2 2018-06-14 02:07:30 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5428

Re: loading or refreshing calendars to server

I'm not sure your code makes much sense because you haven't accessed any data to refresh. You could also try calling reset().


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#3 2018-06-14 03:01:26 am

akim
Member
Registered: 2010-04-04
Posts: 77

Re: loading or refreshing calendars to server

Shane Stanley wrote:

I'm not sure your code makes much sense because you haven't accessed any data to refresh.

I wrote the above script to be triggered by a user after a user created a new calendar event with the Calendar app menu commands. I was under the impression that an applescript command to reload calendars then allowed EventKit to identify a new event. In my original script,  EventKit did not recognize a new event, absent Calendar app's applescript command to reload calendars.

Shane Stanley wrote:

You could also try calling reset().

In regard to your suggestion, my attempt at the following script

Applescript:

set the theEKEventStoreReset to theEKEventStore's reset()

yielded no apparent result, in the context I was describing.

Can you clarify your script recommendation?

Offline

 

#4 2018-06-14 03:42:11 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5428

Re: loading or refreshing calendars to server

akim wrote:

I wrote the above script to be triggered by a user after a user created a new calendar event with the Calendar app menu commands.



The problem, I suspect, is that you're at the mercy of Calendar.app and when it is going to commit any changes. Reloading is aimed at the calendar store, not any other clients who may also be accessing it.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#5 2018-06-14 06:46:52 pm

akim
Member
Registered: 2010-04-04
Posts: 77

Re: loading or refreshing calendars to server

How do I have EventKit or Calendar app commit an event, if I have an event that a user has created via the Calendar app's user interface, but that apparently has not been committed?
The following EK Event Store's function to save an event by committing it, requires an event that has already been committed.

Applescript:

set {theResult, theError} to theEKEventStore's saveEvent:theEvent span:true commit:true |error|:(reference)

Any ideas on how to proceed on committing an uncommitted event?

Offline

 

#6 2018-06-14 08:17:03 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5428

Re: loading or refreshing calendars to server

akim wrote:

How do I have EventKit or Calendar app commit an event, if I have an event that a user has created via the Calendar app's user interface, but that apparently has not been committed?



I don't believe you can, other than perhaps quitting Calendar.app, or doing something else to it that makes it save.

What you're dealing with is a short-coming of Calendar.app -- there should be some kind of save or commit scripting command.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)