i am trying to copy ical entries from one calendar to another using the following script:

tell application "iCal"
set localEvents to events of calendar "Privat"
set remoteEvents to events of calendar "owncloud"
repeat with theEvent in localEvents
if theEvent is not in remoteEvents then
copy theEvent to end of remoteEvents
end if
end repeat
end tell

Doesn't an event get a new id if it's moved into a different calendar? In this case if theEvent is not in remoteEvents will always be true.
–
patrix♦Mar 15 '13 at 15:31

so how can i copy new events, without re-copying events that have been copied before? this script is supposed to run once every day.
–
mcnesiumMar 17 '13 at 13:21

What prevents you from creating the events in the target calendar directly?
–
patrix♦Mar 17 '13 at 13:41

the owncloud calendar is on a caldav server (owncloud) and (therefore?) not available for syncing with iSync.app.this script is only part of a sync-script that first starts iSync to sync my phone with the privat calendar and then copy the events to the owncloud calendar.
–
mcnesiumMar 18 '13 at 8:41

1 Answer
1

This is what I have so far. All works ok, except for my duplicate check. Just receiving tell statement for "Event Discarded: Old.". When this is not the case. Any Help?

to getRecurrenceTermination(startDate, recurrenceString)
set olddel to AppleScript's text item delimiters
set AppleScript's text item delimiters to ";"
set tItems to text items of recurrenceString
set AppleScript's text item delimiters to "="
set d to 0
set untl to missing value
repeat with anItem in tItems
set parts to text items of anItem
set sec to word 3 of anItem
if (offset of "FREQ=" in anItem) > 0 then
if (offset of "WEEKLY" in anItem) > 0 then
set d to 7
else if (offset of "DAILY" in anItem) > 0 then
set d to 1
else if (offset of "MONTHLY" in anItem) > 0 then
set d to 31
end if
else if (offset of "INTERVAL=" in anItem) > 0 then
set d to d * sec
else if (offset of "COUNT=" in anItem) > 0 then
set d to d * sec
else if (offset of "UNTIL=" in anItem) > 0 then
set untl to current date
set untl's year to text 1 thru 4 of sec
set untl's month to text 5 thru 6 of sec
set untl's day to text 7 thru 8 of sec
set untl's hours to text 10 thru 11 of sec
set untl's minutes to text 12 thru 13 of sec
set untl's seconds to text 13 thru 14 of sec
end if
end repeat
set AppleScript's text item delimiters to olddel
if untl is missing value then
if d is not 0 then
set finalDate to startDate + (d * days)
else
set finalDate to startDate + (1000 * days)
end if
else
set finalDate to untl
end if
return finalDate
end getRecurrenceTermination
tell application "iCal"
set TheCalendars to name of calendars
set theSourceCalendar to ""
set theDestinationCalendar to ""
choose from list TheCalendars with title "Please select a source calendar" without empty selection allowed
set theSourceCalendar to result as string
if theSourceCalendar is "" then
--do nothing
else
set theOtherCals to {}
repeat with anItem in TheCalendars
if (anItem as string) is not (theSourceCalendar as string) then set theOtherCals to theOtherCals & anItem
end repeat
choose from list theOtherCals with title "Please select a destination calendar" without empty selection allowed
set theDestinationCalendar to result as string
if theDestinationCalendar is "" then
--do nothing
else
display dialog "Copy calendar events from " & theSourceCalendar & " to " & theDestinationCalendar & "?" buttons {"OK", "Cancel"} default button 2
if the button returned of the result is "OK" then
set TheEvents to events of calendar theSourceCalendar
set otherEvents to events of calendar theDestinationCalendar
repeat with anEvent in TheEvents
set curDate to current date
set isNew to 1
set startDate to start date of anEvent
set endDate to end date of anEvent
set eventStatus to status of anEvent
set recuInfo to recurrence of anEvent
set auid to uid of anEvent
if recuInfo is not missing value then
set ed to my getRecurrenceTermination(startDate, recuInfo)
end if
if endDate ≥ curDate and eventStatus is not none then
--check that is not already existing using uid of events
repeat with oEvent in otherEvents
set ouid to uid of oEvent
if ouid is equal to auid then
set isNew to 0
exit repeat
end if
end repeat
if isNew is not 0 then
duplicate anEvent to end of calendar theDestinationCalendar
end if
else
log "Event discarded: old"
end if
end repeat
else
--do nothing
end if
end if
end if
end tell

I believe the duplicate check problem flagging, when no duplicates exist is maybe because of this?