-
-
Save pwc3/5342337 to your computer and use it in GitHub Desktop.
tell application "Calendar" | |
-- delete everything from the destination calendar | |
-- TODO: Change "Destination Calendar" to be the name of your destination calendar | |
repeat with anEvent in (get events of calendar "Destination Calendar") | |
delete anEvent | |
end repeat | |
-- copy all events from the source calendar to the destination | |
-- TODO: Change "Source Calendar" to be the name of your source calendar | |
-- TODO: Change "Destination Calendar" to be the name of your destination calendar | |
repeat with anEvent in (get events of calendar "Source Calendar") | |
copy anEvent to the end of events of calendar "Destination Calendar" | |
end repeat | |
end tell |
Jumping on an old string here, but hoping someone is still watching. -- I have 2 different work calendars and a personal calendar that I need to keep in sync. It isn't sufficient for me to be able to view them, I need them to be mirror each other. This seems like a start to a good sync service, but I'm struggling (admittedly a novice here) to determine how I can set it up to not keep copying the same events over and over.
Hi!
I played some hour with the topic at it has some infuriating problems.
- First, AppleScript drops an error of missing handler for uids of calendars, and many properties of the events (url, allday event, location and so).
- The other problem is recurrence - it was impossible to copy from an Exchange calendar to an icloud cal. It is a string, but the string from one event as a copy to the new event raises 1700 error code (Bad parameter data was detected or there was a failure while performing a coercion.)
- Other issue is the fields with missing value, you see the code
I hope you can use the code below, but it is far to be perfect. I also planned to have a script which list the calendars and their uids to make the code target really the one you need, but the missing handler made it impossible.
set theStartDate to (current date) - (20 * days)
set hours of theStartDate to 0
set minutes of theStartDate to 0
set seconds of theStartDate to 0
set theEndDate to theStartDate + (14 * days) - 1
set sourceCalendarTitle to "YourSourceCalendarTitle"
set destinationCalendarTitle to "YourDestinationCalendarTitle"
tell application "Calendar"
set destinationCalendar to (first calendar where its title = destinationCalendarTitle)
set sourceCalendar to (first calendar where its title = sourceCalendarTitle)
tell destinationCalendar
set calendarEvents to (every event where its start date is greater than or equal to theStartDate and end date is less than or equal to theEndDate)
set numberOfEvents to count calendarEvents
repeat with i from 1 to numberOfEvents
set anEvent to item i of calendarEvents
delete anEvent
end repeat
end tell
tell sourceCalendar
set sourceEvents to (every event where its start date is greater than or equal to theStartDate and end date is less than or equal to theEndDate)
repeat with i from 1 to count sourceEvents
set anEvent to item i of sourceEvents
set tmpDescription to description of anEvent
if tmpDescription = missing value then
set tmpDescription to ""
end if
if recurrence of anEvent = missing value then
make new event at destinationCalendar with properties {summary:summary of anEvent, start date:start date of anEvent, end date:end date of anEvent, description:tmpDescription, allday event:allday event of anEvent}
end if
end repeat
end tell
end tell
it works with BigSur on mbp M1. thank you
... the problem is that it misses recurring events whose first event does not happen inside the selected time window
sadly non of this works for me (Big Sur, MBP M1)
Hi, I needed this feature, so I created an updated version for anyone interested (compatible with the current macOS version): https://gist.github.com/MyKEms/3287c65f097a29b1756f3799842165bb
This script handles recurring events.
It was written to copy events on an ongoing basis, skip duplication, and get recurring events.
https://gist.github.com/scottwils/256b5658a094a295b88585c1215c12f4
Alright, I'm not sure exactly what the problem was, or if I fixed it completely, but if I change the line;
To this;
It looks like the problem goes away. I changed
copy
toduplicate
which I think is just an alias. I copied directly to the destination calendar instead of the events of the destination calendar, which doesn't seem to have made a difference, but I like that better. And I addedwith properties
which I think is what fixed the issue. I think updating the properties prevents something from thinking this might be an existing event and skipping it. That's just a guess, I haven't really confirmed, but I figured all of this may be useful to someone else.