calendar – AppleScript – Discover Recurring occasions inside date vary

[ad_1]

I’m making an attempt to make a mirror of 1 calendar into one other for the a set time frame (say 1 week). Nevertheless once I run the script under it solely copies non-recurring occasions. Any tips on learn how to repair that is a lot appreciated

use AppleScript model "2.4" -- Yosemite (10.10) or later
use scripting additions

set SourceCalendarName to "VV Major"
set DestinationCalendarName to "VV Mirror"
set meetingProxy to "VV Assembly"
set in the present day to present date

set numberofdays to 7
set startDay to ((present date) - (1 * days))
set time of startDay to 0
set endDay to ((startDay) + (numberofdays * days))
--set time of endDay to 

set numberOfEventsAdded to 0



inform utility "Calendar"
    
    set sourceCalendar to calendar SourceCalendarName
    set destinationCalendar to calendar DestinationCalendarName
    
    (*
    inform destinationCalendar
        delete (occasions)
    finish inform
    *)
    
    set sourceEventList to (occasions of sourceCalendar the place (its begin date > startDay) and (its begin date < endDay))
    
    repeat with eventIdx from 1 to size of sourceEventList
        
        set newEvent to merchandise eventIdx of sourceEventList
        
        --repeat with newEvent in (get occasions of sourceCalendar whose (begin date is larger than startDay) and (begin date is lower than endDay))
        
        set existingEventList to (occasions of destinationCalendar)
        
        set eventExists to false
        
        if size of existingEventList shouldn't be 0 then
            repeat with checkEvent in existingEventList
                
                if ((begin date of checkEvent = begin date of newEvent) and (finish date of checkEvent = finish date of newEvent)) then
                    set eventExists to true
                    exit repeat
                finish if
                
            finish repeat
        finish if
        
        if eventExists is fake then
            inform destinationCalendar
                set destEvent to (make new occasion at finish of occasions with properties {begin date:begin date of newEvent, finish date:finish date of newEvent, abstract:meetingProxy, allday occasion:allday occasion of newEvent, description:(uid of newEvent as textual content)})
                if recurrence of destEvent shouldn't be lacking worth then
                    set recurrence of destEvent to recurrence of newEvent
                finish if
                
            finish inform
        finish if
        
        --set numberOfEventsAdded to (numberOfEventsAdded + 1)
        
        
    finish repeat
finish inform

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *