I’m looking to copy Cal A) to Cal B)
without Cal B) having any duplicates.
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 "Calendar"
set TheCalendars to name of calendars
set theSourceCalendar to "Testing"
set theDestinationCalendar to "Testing1"
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
display dialog "Start Copy? " & theSourceCalendar & " to " & theDestinationCalendar & "?" buttons {"Yes", "No"} default button 1
if the button returned of the result is "Yes" 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 tell
end
Ok, so after working on my script into the wee hours of the night… I have concluded that removal of this was in order.
and
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 "Calendar"
set TheCalendars to name of calendars
set theSourceCalendar to "IndyCom - Company"
set theDestinationCalendar to "IndyCom"
display dialog "Start Copy? " & theSourceCalendar & " to " & theDestinationCalendar & "?" buttons {"Yes", "No"} default button 1
if the button returned of the result is "Yes" 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 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)
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 tell
end
Hmm…
for some reason
Is flagging the same UID’s… am I doing something wrong? (Event Log)
Hi. I don’t have an event id property in my version, but I’m also using an ancient OS. I’m not certain that I’ve understood your problem, but I think you’re just trying to isolate the UIDs across calendars; if that’s incorrect, you might want to expound on your goal, rather than posting swaths of uncommented code.
tell application "iCal"
set {source, destination} to {calendar "home", calendar "untitled"}--adjust as needed
duplicate (source's events whose uid is not in my (destination's events's uid)) to destination's end
end tell