0 votos

AppleScript - Encuentra eventos recurrentes dentro de un rango de fechas

Estoy tratando de hacer un espejo de un calendario en otro por un período de tiempo establecido (digamos 1 semana). Sin embargo, cuando ejecuto el script a continuación, solo copia eventos no recurrentes. Cualquier sugerencia sobre cómo solucionar esto es muy apreciada

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

set SourceCalendarName to "VV Main"
set DestinationCalendarName to "VV Mirror"
set meetingProxy to "VV Meeting"
set today to current date

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

set numberOfEventsAdded to 0

tell application "Calendar"

    set sourceCalendar to calendar SourceCalendarName
    set destinationCalendar to calendar DestinationCalendarName

    (*
    tell destinationCalendar
        delete (events)
    end tell
    *)

    set sourceEventList to (events of sourceCalendar where (its start date > startDay) and (its start date < endDay))

    repeat with eventIdx from 1 to length of sourceEventList

        set newEvent to item eventIdx of sourceEventList

        --repeat with newEvent in (get events of sourceCalendar whose (start date is greater than startDay) and (start date is less than endDay))

        set existingEventList to (events of destinationCalendar)

        set eventExists to false

        if length of existingEventList is not 0 then
            repeat with checkEvent in existingEventList

                if ((start date of checkEvent = start date of newEvent) and (end date of checkEvent = end date of newEvent)) then
                    set eventExists to true
                    exit repeat
                end if

            end repeat
        end if

        if eventExists is false then
            tell destinationCalendar
                set destEvent to (make new event at end of events with properties {start date:start date of newEvent, end date:end date of newEvent, summary:meetingProxy, allday event:allday event of newEvent, description:(uid of newEvent as text)})
                if recurrence of destEvent is not missing value then
                    set recurrence of destEvent to recurrence of newEvent
                end if

0voto

Jintoku Puntos 9

Parece que uno necesita usar CalendarLibEC de Shane (https://latenightsw.com/freeware/)

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

use scripting additions

-- Cambiar variables abajo
set SourceCalendarName to "VV Main"
set DestinationCalendarName to "VV Mirror"
set meetingProxy to "VV Meeting"
set addRecurringEvents to false
set numberofdays to 7

-- No deberían ser necesarios cambios debajo, pero proceda bajo su propio riesgo

set today to current date

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

set numberOfEventsAdded to 0
set numberofEventsFailedtoCopy to 0

set theStore to («event !Cls!fst»)
-- El guión original solo compara las fechas de inicio y fin de los eventos.
set destCal to («event !CLs!fca» DestinationCalendarName given «class !Cty»:«constant !Tct!TtC», «class !Cst»:theStore) -- cambiar tipo de calendario según corresponda
set existingEventList to («event !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 («event !CLs!inf» given «class !Cev»:thisEvent)
    set thisEvent's contents to {startDate, endDate}
end repeat

set existingEventDates to existingEventList -- Usar una variable diferente para mayor claridad.

-- Obtener los eventos del calendario fuente que caen dentro del mismo rango de fechas.
set sourceCal to («event !CLs!fca» SourceCalendarName given «class !Cty»:«constant !Tct!TtC», «class !Cst»:theStore) -- cambiar según corresponda
set sourceEventList to («event !CLs!feS» given «class !Csd»:startDay, «class !Ced»:endDay, «class !Csc»:{sourceCal}, «class !Cst»:theStore)
repeat with eventIdx from 1 to length of sourceEventList
    set newEvent to item eventIdx of sourceEventList
    -- Obtener los datos de interés para cada evento fuente.\
    try
        set {event_external_ID:eventID, event_start_date:startDate, event_end_date:endDate, all_day:isAllday, event_is_recurring:isRecurring} to («event !CLs!inf» given «class !Cev»:newEvent)

        -- Si sus fechas de inicio y fin no están en existingEventDates, crear un nuevo evento usando la aplicación Calendar..
        if (existingEventDates does not contain {{startDate, endDate}}) then

            tell application "Calendar"
                set destEvent to (make new event at end of calendar DestinationCalendarName's events with properties {start date:startDate, end date:endDate, summary:meetingProxy, allday event:isAllday})

                if addRecurringEvents is true then
                    if (isRecurring) then
                        set destEvent's recurrence to recurrence of event id eventID of calendar SourceCalendarName
                    end if
                end if

                set end of existingEventDates to {startDate, endDate} -- si es necesario
                set numberOfEventsAdded to numberOfEventsAdded + 1
            end tell

        end if

    on error errMsg number -10000 --*** -L_NSDictionaryM setObject:forKey:]: object cannot be nil (key: event_creation_date) 
        set eventIdx to {eventIdx + 1}
        set numberofEventsFailedtoCopy to (numberofEventsFailedtoCopy + 1)

    end try

end repeat

AppleAyuda.com

AppleAyuda es una comunidad de usuarios de los productos de Apple en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X