0 votos

Applescript - Encuentra si el evento del calendario ya existe

Estoy tratando de crear un script que copie eventos de mi calendario laboral a uno personal pero solo como bloques de tiempo para que mi cónyuge sepa cuando tengo reuniones. Después de buscar en internet un poco, llegué al siguiente script que funciona en su mayor parte.

set SourceCalendarName to "Trabajo"
set DestinationCalendarName to "Espejo"
set today to current date

set numberofdays to 7
set startday to ((current date) - (1 * days))
set endday to ((current date) + (numberofdays * days))

tell application "Calendario"

    set sourceCalendar to calendar SourceCalendarName
    set destinationCalendar to calendar DestinationCalendarName

    -- Copiar eventos de la fuente al destino --
    repeat with sourceEvent in (get events of sourceCalendar whose (start date is greater than or equal to startday) and (start date is less than endday))

        tell sourceEvent
            set |allday event| to allday event
            set |start date| to start date
            set |end date| to end date
            set |recurrence| to recurrence
            set |description| to description
            set |summary| to summary
            set |status| to status
            set |summary| to "Reunión VV"

        end tell

        delete (events of destinationCalendar whose start date is equal to |start date| and end date is equal to |end date|)
        tell destinationCalendar
            set destEvent to (make new event at end of events with properties {start date:|start date|, end date:|end date|, summary:|summary|})
        end tell

    end repeat
end tell

Estoy tratando de no tener la parte de eliminar eventos, pero comprobar si ya existe un evento y no molestar en crear un evento en primer lugar

delete (events of destinationCalendar whose start date is equal to |start date| and end date is equal to |end date|)

¿Alguna idea de cómo modificar esto a una condición 'if' para que el 'tell' del evento sea opcional?

Gracias

0voto

Jintoku Puntos 9

Aquí está lo que funcionó

--Ejecutándose bajo AppleScript 2.8, MacOS 15.0
set SourceCalendarName to "Work"
set DestinationCalendarName to "VV Mirror"
set today to current date

set numberofdays to 7
set startday to ((current date) - (1 * days))
set endday to ((current date) + (numberofdays * days))

tell application "Calendar"

    set sourceCalendar to calendar SourceCalendarName
    set destinationCalendar to calendar DestinationCalendarName

    -- Copiar eventos de la fuente al destino --
    repeat with sourceEvent in (get events of sourceCalendar whose (start date is greater than startday) and (start date is less than endday))

        tell sourceEvent
            set |allday event| to allday event
            set |start date| to start date
            set |end date| to end date
            set |status| to status
            set |summary| to "VV Meeting"
            set |recurrence| to recurrence
        end tell

        set existingevent to (events of destinationCalendar whose start date is equal to |start date| and end date is equal to |end date|) as list

        if length of existingevent is 0 then
            tell destinationCalendar
                set destEvent to (make new event at end of events with properties {start date:|start date|, end date:|end date|, summary:|summary|, allday event:|allday event|, recurrence:|recurrence|})
            end tell
        end if

    end repeat
end tell

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