22.3 C
New York
Tuesday, September 17, 2024

calendar – AppleScript – Discover Recurring occasions inside date vary


Appears to be like like one wants to make use of CalendarLibEC from Shane (https://latenightsw.com/freeware/)

use script "CalendarLib EC" model "1.1.5"
use AppleScript model "2.4" -- Yosemite (10.10) or later

use scripting additions


-- Change variables beneath
set SourceCalendarName to "VV Important"
set DestinationCalendarName to "VV Mirror"
set meetingProxy to "VV Assembly"
set addRecurringEvents to false
set numberofdays to 7

-- Modifications shouldn't be required beneath, however proceed at your personal danger

set at present to present date

set startDay to (at present)
set time of startDay to 0
set endDay to (startDay + (numberofdays * days))

set numberOfEventsAdded to 0
set numberofEventsFailedtoCopy to 0

set theStore to («occasion !Cls!fst»)
-- The unique script solely compares occasions' begin and finish dates.
set destCal to («occasion !CLs!fca» DestinationCalendarName given «class !Cty»:«fixed !Tct!TtC», «class !Cst»:theStore) -- change calendar sort to swimsuit
set existingEventList to («occasion !CLs!feS» given «class !Csd»:startDay, «class !Ced»:endDay, «class !Csc»:{destCal}, «class !Cst»:theStore)

repeat with thisEvent in existingEventList
    set {event_start_date:startDate, event_end_date:endDate} to («occasion !CLs!inf» given «class !Cev»:thisEvent)
    set thisEvent's contents to {startDate, endDate}
finish repeat

set existingEventDates to existingEventList -- Use a distinct variable now for readability.

-- Get the supply calendar occasions which fall inside the identical date vary.
set sourceCal to («occasion !CLs!fca» SourceCalendarName given «class !Cty»:«fixed !Tct!TtC», «class !Cst»:theStore) -- change to swimsuit
set sourceEventList to («occasion !CLs!feS» given «class !Csd»:startDay, «class !Ced»:endDay, «class !Csc»:{sourceCal}, «class !Cst»:theStore)
repeat with eventIdx from 1 to size of sourceEventList
    set newEvent to merchandise eventIdx of sourceEventList
    -- Get the info of curiosity for every supply occasion.
    strive
        set {event_external_ID:eventID, event_start_date:startDate, event_end_date:endDate, all_day:isAllday, event_is_recurring:isRecurring} to («occasion !CLs!inf» given «class !Cev»:newEvent)
        
        -- If its begin and finish dates aren't in existingEventDates, create a brand new occasion utilizing the Calendar appplication..
        if (existingEventDates doesn't comprise {{startDate, endDate}}) then
            
            inform software "Calendar"
                set destEvent to (make new occasion at finish of calendar DestinationCalendarName's occasions with properties {begin date:startDate, finish date:endDate, abstract:meetingProxy, allday occasion:isAllday})
                
                if addRecurringEvents is true then
                    if (isRecurring) then
                        set destEvent's recurrence to recurrence of occasion id eventID of calendar SourceCalendarName
                    finish if
                finish if
                
                set finish of existingEventDates to {startDate, endDate} -- if required
                set numberOfEventsAdded to numberOfEventsAdded + 1
            finish inform
            
        finish if
        
    on error errMsg quantity -10000 --*** -L_NSDictionaryM setObject:forKey:]: object can't be nil (key: event_creation_date) 
        set eventIdx to {eventIdx + 1}
        set numberofEventsFailedtoCopy to (numberofEventsFailedtoCopy + 1)
        
    finish strive
    
finish repeat

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles