• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting calendar - UIDs and moving from one cal to another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting calendar - UIDs and moving from one cal to another


  • Subject: Re: Scripting calendar - UIDs and moving from one cal to another
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 01 Dec 2015 22:07:12 +1100

On 1 Dec 2015, at 6:20 PM, Jay Louvion <email@hidden> wrote:

Your answer doesn’t seem to contradict my impression and the general idea of my new scripts.

No. In practice, the IDs should be unique; a clash is highly unlikely in your situation. And calendar ids are always unique.

But my main question remains: is there a hack to change the calendar of an event from one to another? i.e. literally “move” an event from one calendar to another, without going through the create-delete process ?

Have you tried using the move command?

Otherwise try this (untested) -- pass the event id and the destination calendar id:

use scripting additions
use framework "Foundation"
use framework "EventKit"

on moveEventID:eventID toCalID:calID
-- create event store and get the OK to access Calendars
set theEKEventStore to current application's EKEventStore's alloc()'s init()
theEKEventStore's requestAccessToEntityType:0 completion:(missing value)


-- check if app has access; this will still occur the first time you OK authorization
set authorizationStatus to current application's EKEventStore's authorizationStatusForEntityType:0 -- work around enum bug
if authorizationStatus is not 3 then
display dialog "Access must be given in System Preferences" & linefeed & "-> Security & Privacy first." buttons {"OK"} default button 1
tell application "System Preferences"
activate
tell pane id "com.apple.preference.security" to reveal anchor "Privacy"
end tell
error number -128
end if


set theCalendar to theEKEventStore's calendarWithIdentifier:calID
set theEvent to (theEKEventStore's calendarItemsWithExternalIdentifier:eventID)'s firstObject()
theEvent's setCalendar:theCalendar
set {theResult, theError} to theEKEventStore's saveEvent:theEvent span:((current application's EKSpanThisEvent) + (current application's EKSpanFutureEvents as integer)) commit:true |error|:(reference)
if not theResult as boolean then error (theError's localizedDescription() as text)
end moveEventID:toCalID:

You can change it to use the calendar name easily enough.

And I forgot to thank you for those very precious precisions, Shane - I think I’m a tad impatient to find a solution.
And where do you get such complete documentation? ADP?

I'm getting it from the documentation in Xcode, but you can search for it on the Web. However, it's not all in one place: you really need to look at EKEventStore, EKObject, EKCalendarItem and EKCalendar, as well as the Calendars and Reminders Programming Guide.

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>

 _______________________________________________
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

  • Prev by Date: Re: How Do You Guys Manage Development/Installation of Complex Applescript Projects?
  • Next by Date: make server folder windows a different color than local?
  • Previous by thread: Re: How Do You Guys Manage Development/Installation of Complex Applescript Projects?
  • Next by thread: Re: Scripting calendar - UIDs and moving from one cal to another
  • Index(es):
    • Date
    • Thread