Skip to content

Instantly share code, notes, and snippets.

@kgoggin
Last active Aug 29, 2015
Embed
What would you like to do?
One-way sync two calendars within OS X Calendar app. In this case, used to move events from an Exchange account to an iCloud account.
property today : current date
property bfCal : "*NAME OF SOURCE CALENDAR*"
property iCal : "*NAME OF DESTINATION CALENDAR*"
-- used for Growl notification
property allNotifications : {}
tell application "Calendar" to launch
tell application "Calendar" to reload calendars
-- wait for reload to happen
delay 30
tell application "Calendar"
set iEvents to events of calendar iCal
set bfEvents to events of calendar bfCal
-- delete existing events in source calendar
repeat with calEvent in iEvents
delete calEvent
end repeat
repeat with calEvent in bfEvents
-- copy over all recurring events
if recurrence of calEvent is not missing value then
copy calEvent to end of events of calendar iCal
-- otherwise, only copy events occuring today or in the future
else if start date of calEvent ≥ today then
copy calEvent to end of events of calendar iCal
end if
end repeat
end tell
-- trigger Growl notification
growl("CalSync", "Calendars have been syncd")
on growl(theTitle, theContent)
if allNotifications does not contain theTitle then
set allNotifications to allNotifications & theTitle
end if
set myName to path to me as text
set TID to text item delimiters
set text item delimiters to ":"
set myName to the last text item of myName
set text item delimiters to TID
tell application id "com.Growl.GrowlHelperApp"
register as application myName ¬
all notifications allNotifications ¬
default notifications allNotifications ¬
icon of application "Calendar"
notify with name theTitle ¬
title theTitle ¬
description theContent ¬
application name myName
end tell
end growl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment