Saturday, November 23, 2024

Applescript – Discover if the calendar occasion already exists

I’m attempting to create a script that copies occasions from my work calendar to a private however simply as time blocks in order that my partner is aware of when I’ve conferences. From scouring the web for a bit I got here up with the next script which works for probably the most half.

set SourceCalendarName to "Work"
set DestinationCalendarName to "Mirror"
set right now to present date

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

inform software "Calendar"
    
    set sourceCalendar to calendar SourceCalendarName
    set destinationCalendar to calendar DestinationCalendarName
    
    
    -- Copy sources to vacation spot --
    repeat with sourceEvent in (get occasions of sourceCalendar whose (begin date is bigger than or equal to startday) and (begin date is lower than endday))
        
        
        inform sourceEvent
            set |allday occasion| to allday occasion
            set |begin date| to begin date
            set |finish date| to finish date
            set |recurrence| to recurrence
            set |description| to description
            set |abstract| to abstract
            set |standing| to standing
            set |abstract| to "VV Assembly"
            
        finish inform
        
        
        delete (occasions of destinationCalendar whose begin date is the same as |begin date| and finish date is the same as |finish date|)
        inform destinationCalendar
            set destEvent to (make new occasion at finish of occasions with properties abstract)
        finish inform
        
    finish repeat
finish inform

I’m attempting to not have the delete occasions half however examine if there’s an occasion already and never trouble creating an occasion within the first place

delete (occasions of destinationCalendar whose begin date is the same as |begin date| and finish date is the same as |finish date|)

Any tips on find out how to change this to an if-condition in order that the inform even may be non-obligatory?

Thanks

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles